2013-04-16 122 views
2

我有一個本地的PSQL數據庫設置,並有問題獲得耙分貝:遷移到正常運行。例如,我的數據庫已經有它high_school列名改爲high_school_name,但耙分貝:遷移失敗,狀態顯示如下:Rails遷移 - rake db:status表示遷移已關閉,但數據庫已遷移?

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" 

很明顯,有一個架構問題或什麼。 Schema通過遠程分支進行跟蹤,所以我不知道問題出在哪裏。

回答

3

我懷疑下來不能正確處理列重命名更改,除非只是添加或刪除列。

您可能希望考慮的一個選項實際上是使用SQL更改名稱。例如,如果遷移到high_schoolhigh_school_name失敗並且數據庫本身當前有high_school_name,請將其重命名爲(在SQL中)爲high_school,然後嘗試運行遷移。這可能是您的一個選擇。

+0

謝謝!這工作。 – trevorhinesley

0

在列名正在重命名的行的末尾添加重複零次數