Ruby-on-rails 得到:“迁移正在等待;运行 'bin/rake db:migrate RAILS_ENV=development' 来解决这个问题。” 克隆和迁移项目后
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21309901/
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
Getting: "Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue." after cloning and migrating the project
提问by Stefanos.Ioannou
I cloned my project. Bundled with "bundle install", then run "rake db:migrate". I am getting this error: (when I run the rails server and open my browser to localhost:3000) "Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue."
我克隆了我的项目。与“bundle install”捆绑在一起,然后运行“rake db:migrate”。我收到此错误:(当我运行 Rails 服务器并打开浏览器到 localhost:3000 时)“迁移正在挂起;运行 'bin/rake db:migrate RAILS_ENV=development' 以解决此问题。”
I checked all migrations one by one and all were executed without errors. Also no errors were shown after the execution of "rake db:migrate".
我一一检查了所有迁移,并且所有迁移都没有错误地执行。执行“rake db:migrate”后也没有显示错误。
This is what I see when I execute "rake db:migrate:status"
这是我在执行“ rake db:migrate:status”时看到的
I am on development environment. Please let me know if you need any other information.
我在开发环境。如果您需要任何其他信息,请告诉我。
I also tried "bundle exec rake db:migrate", and "bundle exec rake db:migrate:reset" as "burninggramma" suggested.
我还尝试了“bundle exec rake db:migrate”和“bundle exec rake db:migrate:reset”作为“burninggramma”的建议。
Any clues what causes the error?
任何导致错误的线索?
回答by lewstherin
Interesting. Did you run rake db:create? Assuming you are using sqlite3, do this:
有趣的。你运行rake db:create 了吗?假设您使用的是 sqlite3,请执行以下操作:
rm -f db/*.sqlite3
rake db:create
RAILS_ENV=development rake db:migrate
rails s -e development
Also, can you list the contents of your config/database.ymlfile?
另外,你能列出你的config/database.yml文件的内容吗?
Edit: Warning!Obviously, you will lose your existing data.
编辑:警告!显然,您将丢失现有数据。
回答by Jesus H
After running the migrate command, I still had the same error.
运行 migrate 命令后,我仍然有同样的错误。
What worked for me was to just stop the rails server and start it again.
对我有用的是停止 rails 服务器并重新启动它。
回答by Eich
List your executed migrations with rake db:migrate:statusand look if every migration was executed. You can try to cancel your migration with rake db:abort_if_pending_migrationsand try to migrate again.
列出您执行的迁移rake db:migrate:status并查看是否执行了每个迁移。您可以尝试取消迁移rake db:abort_if_pending_migrations并再次尝试迁移。
回答by p1100i
1.Maybe its default in ruby2/rails4 but have you tried: bundle exec rake db:migrate?
1.也许它在 ruby2/rails4 中是默认的,但你有没有试过:bundle exec rake db:migrate?
2.Another option would be resetting the whole database - use with CAUTION! resets all the data as well- bundle exec rake db:migrate:reset
2.另一种选择是重置整个数据库 -小心使用!也重置所有数据-bundle exec rake db:migrate:reset
+)I would just make sure that you are executing everything in the same development env:
+)我只想确保您在同一个开发环境中执行所有内容:
RAILS_ENV=development bundle exec rake db:migrate:reset
RAILS_ENV=development bundle exec rails s
回答by brntsllvn
Running rake db:migrate RAILS_ENV=testdid it for me
跑步rake db:migrate RAILS_ENV=test为我做到了
回答by Parth Shah
I had the same error in the browser, but upon closely looking at the error message, I noticed some how I had an extra white space in the migrate comment and post files. Once I removed it, it worked perfectly.
我在浏览器中遇到了同样的错误,但仔细查看错误消息后,我注意到在迁移评论和发布文件中我有一些额外的空格。一旦我删除它,它就完美地工作了。
回答by jenstreetman
I got the same error working on the Learn Enough to Be DangerousRails tutorial. I'm using Git Bash terminals on a Windows 10 machine. The error showed up in the terminal where I'm running guard, after I tried to migrate my db using the command (in another terminal):
我在学习足够危险的Rails 教程时遇到了同样的错误。我在 Windows 10 机器上使用 Git Bash 终端。在我尝试使用命令(在另一个终端中)迁移我的数据库后,错误出现在我运行警卫的终端中:
$ bundle exec rake db: migrate:
$ bundle exec rake db: migrate:
After trying the solution offered by @lewstherin, I still got the same error. I tried the command:
在尝试了@lewstherin 提供的解决方案后,我仍然遇到同样的错误。我尝试了以下命令:
$ rails test
And got the explicit and helpful warning:
$ rails test
并得到了明确而有用的警告:
Migrations are pending. To resolve this issue, run:
Migrations are pending. To resolve this issue, run:
bin/rails db:migrate RAILS_ENV=test
I ran the command:
我运行了命令:
$ bin/rails db:migrate RAILS_ENV=test
$ bin/rails db:migrate RAILS_ENV=test
and now I'm working again.
现在我又开始工作了。
回答by zawhtut
Open the database and click schema_migration table. The migrations will be listed as below.

打开数据库并单击 schema_migration 表。迁移将在下面列出。

Sort the version column and find the latest migration you want to go back. Delete or Insert a new one. Rails keeps all the migration history in this table, so you can adjust the migration history to you liking.
对版本列进行排序并找到您要返回的最新迁移。删除或插入一个新的。Rails 将所有迁移历史保存在此表中,因此您可以根据自己的喜好调整迁移历史。
回答by Rafael Rivera
I had this problem and it was because I had my rails files inside a folder named "[rails]". It seems rake doesn't like the following symbols "[]" used in a folder name.
我遇到了这个问题,这是因为我的 rails 文件位于名为“[rails]”的文件夹中。似乎 rake 不喜欢文件夹名称中使用的以下符号“[]”。
Hope this helps others with this issue.
希望这可以帮助其他人解决这个问题。
回答by Malek Zalfana
I'm guessingthe error is that you are creating a table that already exists, I had this problem before. Step 1look into the error when you rake dv:migrate
我猜错误是您正在创建一个已经存在的表,我以前遇到过这个问题。 步骤 1查看 rake dv:migrate 时的错误
Step 2go to the model where this table is created
步骤 2转到创建此表的模型
Step 3add drop_table :[YOUR TABLE] right before the create_table :[YOUR TABLE]
第 3 步在 create_table :[YOUR TABLE] 之前添加 drop_table :[YOUR TABLE]
Step 2run rake db:migrate
步骤 2运行 rake db:migrate
Step 3remove the drop_table once the your migration is done
步骤 3迁移完成后删除 drop_table

