Ruby-on-rails 迁移待定;运行“bin/rake db:migrate RAILS_ENV=development”来解决这个问题[无法继续]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20082002/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:03:17  来源:igfitidea点击:

Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue [unable to proceed]

ruby-on-railsruby

提问by user3010587

I appear to have a circular issue in regards to Ruby on Rails migration procedure. I am following the introduction article and I have reached the point when I need to create my first table.

我似乎有一个关于 Ruby on Rails 迁移过程的循环问题。我正在关注介绍文章,并且已经到了需要创建第一个表的地步。

I have ran the following,

我已经运行了以下,

[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

I then proceeded with the migration,

然后我继续迁移,

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

, however, when I run my application I see the following message,

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

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

but, IF I run the above,

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

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

and the message continues ...

消息还在继续……

I have spent considerable amount of time researching forums in-which the closest I could find was to drop and re-build everything, which have done the following.

我花了大量时间研究论坛——我能找到的最接近的是删除并重新构建所有内容,这些论坛做了以下工作。

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

耙数据库:删除耙数据库:创建耙数据库:迁移

and the results are the same.

结果是一样的。

回答by igaurav

You need to do

你需要做

bundle exec rake test:prepare 

or

或者

bundle exec rake db:test:prepare

and then

进而

bundle exec rake db:migrate

before running the specs

在运行规范之前

Cheers

干杯

cited from : Why am I asked to run 'rake db:migrate RAILS_ENV=test'?

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

回答by Ahmed Ali

you can do

你可以做

bundle exec rake test:prepare 

In Rails 4.1+, they deprecated db:test:prepare You can now just use:

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

ActiveRecord::Migration.maintain_test_schema!

If you need to do it manually

如果您需要手动执行

rake db:schema:load RAILS_ENV=test

and then

进而

bundle exec rake db:migrate

回答by Fábio Mendon?a

try In RAILS_ROOT/config/environments/development.rb Set the following setting to false:

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

config.active_record.migration_error = false#:page_load

config.active_record.migration_error = false#:page_load

回答by fylooi

One weird trick that you can use when your migrations are screwed (file deleted, manually renamed, etc.)

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

  1. Fire up your favourite DB admin tool (eg. PGAdmin3) and browse to the database in question.
  2. Look for a table called schema_migrationsand browse its content. It should have a single column called version. This field is used by Rails to check whether migrations are up to date.
  3. Make sure that your migration timestamps corresponds with the data in this column. If you have deleted an older migration, delete the corresponding timestamp.
  1. 启动您最喜欢的数据库管理工具(例如 PGAdmin3)并浏览到有问题的数据库。
  2. 查找名为的表schema_migrations并浏览其内容。它应该有一个名为version. Rails 使用此字段来检查迁移是否是最新的。
  3. 确保您的迁移时间戳与此列中的数据一致。如果您删除了较旧的迁移,请删除相应的时间戳。

回答by t34mrh0

Check to make sure that table doesn't already exist:

检查以确保该表不存在:

  1. type - rails dbconsole
  2. type - .tables (check to see if there was an error during the rake db:migrate that has the table name like -- create_table(:test) rake aborted!)
  3. If you see the table name after running the .tables in the console type - drop table TABLENAME;
  4. Then .quit to go back to the branch and run the rake db:migrate command again.
  1. 类型 - rails dbconsole
  2. 输入 - .tables(检查 rake db:migrate 期间是否有错误,表名类似于 -- create_table(:test) rake aborted!)
  3. 如果在控制台类型中运行 .tables 后看到表名 - drop table TABLENAME;
  4. 然后 .quit 返回分支并再次运行 rake db:migrate 命令。

回答by Jeremiah Adelaja

this was what i did:

这就是我所做的:

rails db:environment:set RAILS_ENV=test

If you need to do it manually

如果您需要手动执行

rake db:schema:load RAILS_ENV=test

and then

进而

bundle exec rake db:migrate

Thanks to Ahmed Ali....... your comment was helpful.

感谢艾哈迈德·阿里......你的评论很有帮助。