ruby-on-rails – 为什么首先使用Capistrano运行db:migrate?
我正在使用Capistrano第一次部署到生产中,当我跑步时我遇到了错误
上限生产部署 错误是: ** Invoke deploy:migrate (first_time) ** Invoke deploy:set_rails_env ** Execute deploy:migrate DEBUG [048f89c6] Running /usr/bin/env if test ! -d /home/deployer_user/apps/ap_production/releases/20140209005208; then echo "Directory does not exist '/home/deployer_user/apps/ap_production/releases/20140209005208'" 1>&2; false; fi on eslope.net DEBUG [048f89c6] Command: if test ! -d /home/deployer_user/apps/ap_production/releases/20140209005208; then echo "Directory does not exist '/home/deployer_user/apps/ap_production/releases/20140209005208'" 1>&2; false; fi DEBUG [048f89c6] Finished in 0.160 seconds with exit status 0 (successful). INFO [52f75214] Running ~/.rbenv/bin/rbenv exec bundle exec rake db:migrate on eserver.net DEBUG [52f75214] Command: cd /home/deployer_user/apps/ap_production/releases/20140209005208 && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.0 RAILS_ENV=production ~/.rbenv/bin/rbenv exec bundle exec rake db:migrate ) DEBUG [52f75214] rake aborted! DEBUG [52f75214] An error has occurred,this and all later migrations canceled: DEBUG [52f75214] DEBUG [52f75214] PG::UndefinedTable: ERROR: relation "client_infos" does not exist DEBUG [52f75214] : ALTER TABLE "client_infos" RENAME TO "clients 这个错误实际上是完全合理的.引用的表不存在.我不明白为什么迁移正在运行?为什么不在第一次运行时从模式创建数据库.我是否无意中删除了一个说明已运行迁移的文件?只是删除它,或“.gitignoring”它? 我想我知道如何解决它(rake db:create或者类似)但是我不明白的是,如果在Capistrano v3它知道它是第一次,为什么它不会直接使用架构而不是运行所有迁移?我是一个菜鸟,这似乎是合理的,但另一方面,运行迁移会获得相同的结果,所以……(但是那些不会盲目地在生产中使用迁移的人们呢?不会他们被卡住?)谢谢. 解决方法
db:migrate获取迁移文件并执行它们.
所以如果一个表不存在,它会告诉你这样的.如果您的部署是第一次部署到该计算机,或者配置的数据库尚未初始化,您应该: >创建数据库 rake db:create 这将创建所有表 2运行迁移 `rake db:migrate` 显然,您需要进行迁移. 强烈建议不要加载模式(除非你别无选择),因为在(回滚等)之后很难处理模式,但如果你别无选择,你可以做rake db:schema:load 有关详细信息,请参阅此 rake db:schema:load vs. migrations How to update production database schema safely in rails 3.1.3? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |