Rails迁移 - rake db:status表示迁移已关闭,但数据库已经迁移?

时间:2013-04-16 20:09:38

标签: ruby-on-rails postgresql migration rake

我有一个本地PSQL数据库设置,并且遇到了rake db:migrate正常运行的问题。例如,我的数据库已将其high_school列名更改为high_school_name,但rake db:migrate失败,状态显示为:

up     20130307043554  Adding seo tables
up     20130307185401  Create admin notes
up     20130307185402  Move admin notes to comments
up     20130308160956  Add active flad to users
up     20130308214928  Add column public to users table
up     20130325203837  Add duration to videos
up     20130326171803  Update duration of videos
down    20130410145000  Fix high school name
up     20130410145028  Add high school id to users
up     20130410161705  Convert units for stats
up     20130410164209  ********** NO FILE **********
up     20130416142844  Add column coach id to users

为什么迁移顺序中间的迁移失败/被视为“关闭”?这是错误:

Migrating to AddingSeoTables (20130307043554)
Migrating to CreateAdminNotes (20130307185401)
Migrating to MoveAdminNotesToComments (20130307185402)
Migrating to AddActiveFladToUsers (20130308160956)
Migrating to AddColumnPublicToUsersTable (20130308214928)
Migrating to AddDurationToVideos (20130325203837)
Migrating to UpdateDurationOfVideos (20130326171803)
Migrating to FixHighSchoolName (20130410145000)
(0.1ms)  BEGIN
==  FixHighSchoolName: migrating ==============================================
-- rename_column(:users, :high_school, :high_school_name)
(0.4ms)  ALTER TABLE "users" RENAME COLUMN "high_school" TO "high_school_name"
PG::Error: ERROR:  column "high_school" does not exist
: ALTER TABLE "users" RENAME COLUMN "high_school" TO "high_school_name"
(0.1ms)  ROLLBACK
rake aborted!
An error has occurred, this and all later migrations canceled:

PG::Error: ERROR:  column "high_school" does not exist
: ALTER TABLE "users" RENAME COLUMN "high_school" TO "high_school_name"

显然,存在架构问题或其他问题。虽然架构是通过远程分支跟踪的,但我不知道问题出在哪里。

2 个答案:

答案 0 :(得分:3)

我怀疑down无法正确处理列重命名更改,除非只添加或删除列。

您可能希望考虑的一个选项实际上是使用SQL更改名称。例如,如果将high_school更改为high_school_name的迁移失败且数据库本身当前具有high_school_name,则将其(在SQL中)重命名为high_school,然后尝试运行移民。这可能是您的一个选择。

答案 1 :(得分:0)

将resque nil添加到列重命名的行的末尾