Rails app error - ActiveRecord::PendingMigrationError Migrations are pending; run 'rake db:migrate RAILS_ENV=development' to resolve this issue

生来就可爱ヽ(ⅴ<●) 提交于 2020-02-05 13:35:46

问题


The database is created, tables are created, data are there.

But after I restarted the Rails application, I got this error. The app is using MySQL. What's the issue here?

Thank you in advance


回答1:


Solution

Simply run

rake db:migrate

There are migrations that need to be ran before your server can start. Learn what migrations are and how they are used in Rails with this RailsGuide.

Run that rake db:migrate command any time you make a migration, or any time you create a new project. If you get an error saying that migrations are pending, this is the answer. Then try to start the server again.

Only if that doesn't work, try what is below.

If that doesn't work

Run these commands in this order:

  1. rake db:drop

  2. rake db:create

  3. rake db:migrate

  4. rake db:seed - This one is only necessary if you have seeded data.

Remember, when in doubt: restart the server!




回答2:


just run rake db:migrate then start server, see then what happens, looks like existing migrations are yet not part of schema. Or you schema_migrations table might be missing some version value.




回答3:


Try to run bundle exec rake db:migrate RAILS_ENV=developmentfor me running just bundle exec rake db:migrate didn't resolve the issue




回答4:


As one of the comments above, utilizing the following works for me:

rake db:drop

rake db:create

rake db:migrate

when rake db:migrate or restarting didn't help.



来源:https://stackoverflow.com/questions/24339902/rails-app-error-activerecordpendingmigrationerror-migrations-are-pending-ru

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!