Rails pending migration in rake db:test:prepare

a 夏天 提交于 2019-12-11 04:03:38

问题


I've run rake db:migrate and all of my migrations ran. However, when I try to run rake db:test:prepare I get the error:

You have 1 pending migrations:
  20130724211328 CreateGalleries
Run `rake db:migrate` to update your database then try again.

Then running rake db:migrate again gives the error:

PG::Error: ERROR:  relation "galleries" already exists...

But in the console I can create and manipulate the Gallery model exactly as shown in the CreateGalleries migration. The table is not being created or even mentioned in any other migrations.

It seems the migration ran just fine but did not register. Any ideas how to fix this?

EDIT

I solved this with rake db:drop db:create db:migrate then rake db:test:prepare, but I'm happy to give the solution to anyone who can shed light on what caused the problem in the first place.


回答1:


I suspect the migration for galleries hasn't been executed properly. If you're 100% sure everything is right in your table, you can bump up the migration version to the version of the galleries migration.

To do this, find the timestamp of your galleries migration (the 14 numbers in front of your migration file, in this case 20130724211328) and insert this as a new row into the table schema_migrations (which is done automatically by Rails after successfully executing a migration).

If the table is empty, you could also drop the table galleries and run rake db:migrate again. This way you can also make sure your migration doesn't trigger any errors.



来源:https://stackoverflow.com/questions/17948862/rails-pending-migration-in-rake-dbtestprepare

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