Rails的挂起的迁移在耙分贝:测试:prepare [英] Rails pending migration in rake db:test:prepare

查看:180
本文介绍了Rails的挂起的迁移在耙分贝:测试:prepare的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经运行耙分贝:迁移和我所有的迁移跑了。然而,当我尝试运行耙分贝:测试:prepare 我得到的错误:

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.

然后运行耙分贝:迁移再次给出了错误:

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

但在控制台中,我可以创建和操作完全在CreateGalleries迁移如图所示的画廊模式。该表不正在创建或甚至任何其它迁移提到

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?

修改

我解决了这个与耙分贝:滴分贝:创建DB:迁移然后耙分贝:测试:prepare ,但我很高兴能给予解决的人谁可以阐明什么摆在首位引发的问题光。

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.

推荐答案

我怀疑的画廊迁​​移没有被正确执行。如果你是100%确保一切就在你的表,你可以迁移版本一下子提高到画廊迁移的版本。

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.

要做到这一点,找到你的画廊迁移的时间戳(14个号码中迁移文件的前面,在这种情况下 20130724211328 )并插入这是一个新行到表<​​code> schema_migrations (这是自动Rails的成功执行迁移后进行)。

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.

这篇关于Rails的挂起的迁移在耙分贝:测试:prepare的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆