迁移正在等待中; 运行’bin / rake db:migrate RAILS_ENV = development’来解决此问题

关于Ruby on Rails迁移过程,我似乎有一个循环问题。 我正在关注介绍文章,当我需要创建我的第一个表时,我已达到了这一点。

我跑了以下,

[tims@web2 working_ror]# rails generate model Homepage first_name:string last_name:string email:string message:text invoke active_record create db/migrate/20131119203948_create_homepages.rb create app/models/homepage.rb invoke test_unit createtest /models/homepage_test.rb createtest /fixtures/homepages.yml 

然后我继续进行迁移,

 [tims@web2 working_ror]# rake db:migrate == CreateHomepages: migrating ================================================ -- create_table(:homepages) -> 0.0493s == CreateHomepages: migrated (0.0494s) ======================================= 

但是,当我运行我的应用程序时,我看到以下消息,

 Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue. 

但是,如果我运行上面的,

 [tims@web2 working_ror]# rake db:migrate RAILS_ENV=development [tims@web2 working_ror]# 

并且消息继续……

我花了相当多的时间研究论坛 – 我最接近的就是放弃并重建一切,这些都做了以下工作。

rake db:drop rake db:create rake db:migrate

结果是一样的。

你需要这样做

 bundle exec rake test:prepare 

要么

 bundle exec rake db:test:prepare 

然后

 bundle exec rake db:migrate 

在运行规范之前

干杯

引自: 为什么我要求运行’rake db:migrate RAILS_ENV = test’?

你可以做

 bundle exec rake test:prepare 

在Rails 4.1+中,他们弃用db:test:prepare现在可以使用:

 ActiveRecord::Migration.maintain_test_schema! 

如果您需要手动完成

 rake db:schema:load RAILS_ENV=test 

然后

 bundle exec rake db:migrate 

尝试在RAILS_ROOT / config / environments / development.rb中将以下设置设置为false:

config.active_record.migration_error = false#:page_load

您的迁移被搞砸时可以使用的一个奇怪的技巧(文件删除,手动重命名等)

  1. 启动您最喜欢的数据库管理工具(例如PGAdmin3)并浏览到相关数据库。
  2. 查找名为schema_migrations的表并浏览其内容。 它应该有一个名为version列。 Rails使用此字段来检查迁移是否是最新的。
  3. 确保迁移时间戳与此列中的数据相对应。 如果已删除旧迁移,请删除相应的时间戳。

检查以确保该表尚不存在:

  1. type – rails dbconsole
  2. type – .tables(检查rake db期间是否有错误:具有表名的migrate,如create_table(:test)rake aborted!)
  3. 如果在控制台类型中运行.tables后看到表名 – drop table TABLENAME;
  4. 然后.quit返回分支并再次运行rake db:migrate命令。

这就是我所做的:

 rails db:environment:set RAILS_ENV=test 

如果您需要手动完成

 rake db:schema:load RAILS_ENV=test 

然后

 bundle exec rake db:migrate 

感谢Ahmed Ali …….您的评论很有帮助。