2013-05-14 61 views
3

從重複的遷移恢復由於合併幾個特性分支到我的項目,我有以下遷移:在Django南

0001_initial.py 
0002_auto__add_field_userprofile_telephone__add_field_userprofile_timezone.py 
0003_auto.py 
0004_auto__del_field_organisation_admin.py 
0005_auto__add_field_organisation_permitted_domains.py 
0005_auto__add_field_userprofile_currency.py 

請注意,我有兩個重複0005遷移。這些運行良好,在我的生產系統上部署得很好。

$ python manage.py migrate accounts --list                                        [17:11:42] 

accounts 
    (*) 0001_initial 
    (*) 0002_auto__add_field_userprofile_telephone__add_field_userprofile_timezone 
    (*) 0003_auto 
    (*) 0004_auto__del_field_organisation_admin 
    (*) 0005_auto__add_field_organisation_permitted_domains 
    (*) 0005_auto__add_field_userprofile_currency 

我的表有正確的列:

$ psql 
db_my_project=# \d+ accounts_organisation 
db_my_project=# \d+ accounts_userprofile 
... shows currency and permitted_domain, suggesting the migrations worked correctly 

但是,如果我嘗試創建一個新的遷移,南認爲我還沒有添加列」 permitted_domains'我的模型:

$ python manage.py schemamigration accounts --auto                                      [17:16:15] 
+ Added field permitted_domains on accounts.Organisation 
Created 0006_auto__add_field_organisation_permitted_domains.py. You can now apply this migration with: ./manage.py migrate accounts 

我該如何解決這個問題?

回答

3

從文檔:http://south.readthedocs.org/en/0.7.6/autodetector.html

當autodetector運行時,它與 在您最近上的應用程序遷移凍結當前的模型進行比較,如果發現任何 變化,收益率的一個或多個遷移到南 migration-file-writer。

遷移使字典中的字段的凍結版本保持字典。

因此:

0005_auto__add_field_organisation_permitted_domains組織類將有一個字段permitted_domains0005_auto__add_field_userprofile_currency不會。當您運行:

$ python manage.py schemamigrate accounts --auto 

這會比較反對場店的記錄代碼的當前狀態0005_auto_add_field_userprofile_currency,從而導致南方添加字段第二次。

如果將'allowed_domains'字段的行從0005_auto__add_field_organisation_permitted_domains複製到0005_auto__add_field_userprofile_currency,這將解決您的問題。

+0

對於其他人指的是:不要忘記刪除摺疊的遷移(即,''0005_auto__add_field_organisation_permitted_domains'在這種情況下)來自'south_migrationhistory'表格,否則當你運行'migrate '時你會得到這個錯誤:'我不相信自己;要麼通過擺弄south_migrationhistory表來解決這個問題,要麼將--delete-ghost-migrations傳遞給South,讓它刪除所有這些記錄(這可能不太好)。 – 3cheesewheel 2014-02-13 19:15:24

2

這是一個非常具體的問題,我希望這可以幫助,請執行下列操作:

1)此文件重命名:0005_auto__add_field_organisation_permitted_domains0006_auto__add_field_organisation_permitted_domains

2)自0006重命名您最近遷移文件的數量0007

3)發出命令python manage.py migrate account 0006 --fake欺騙南方。

4)發出命令python manage.py migrate account 0007

可能與您的應用程序

希望這有助於再次獲得南發動機sycn!