2011-06-02 23 views
4

我有一個南方的數據遷移,試圖根據其他模型中找到的數據創建新的對象。當試圖創建一個給定的「目標」模式,我不斷收到一個新的對象:南方數據遷移「實例」錯誤,當使用南方凍結orm

Cannot assign "<ContentType: ContentType object>": "Publishing.content_type" must be a "ContentType" instance. 

看來,有一些錯誤時,經南凍ORM訪問,例如「實例」:

ContentType = orm['contenttypes.ContentType'] 
content_type_kwargs = { 
    'model': ContentModel._meta.module_name, 
    'app_label': ContentModel._meta.app_label, } 
content_type = ContentType.objects.get(**content_type_kwargs) 

# further down 

publishing_kwargs = { 
    'site': Site.objects.get_current(), 
    'publishing_type': publishing_type, 
    'start': start, 
    'content_type': content_type, 
    'object_id': content_object.id, } 

publishing = orm.Publishing(**publishing_kwargs) # Produces the error above 

現在我已經多次驗證content_type實際上是ContentType的一個實例 - 但不知何故,django並不這麼認爲。

  • 實例的「凍結」,南部的orm版本與本地django版本有區別嗎?
  • 這可能是什麼?
+0

Daryl,我面臨同樣的問題goo.gl/I7Jj6您是否設法解決它?我現在試圖使用content_type&object_id在數據遷移中創建一個新實例,但得到上面發佈的確切錯誤。 – Chantz 2011-08-13 18:09:40

回答

8

這是南方處理模型的原因。您需要必須凍結您在遷移時需要使用的任何模型。遷移所在應用程序中的模型會自動凍結;別的你必須手動凍結:

python manage.py schemamigration --auto yourapp --freeze contenttypes 

如果您有需要凍結多個應用程序,重複--freeze說法是需要多次:

python manage.py schemamigration --auto yourapp --freeze contenttypes --freeze someotherapp ... 

另一件事。當您訪問這些額外凍結的模型,你必須使用舊式南API:

orm['contenttypes.contenttype'].objects.all() 

喜歡的東西orm.ContentType將無法​​正常工作。

+0

感謝@ chrisdpratt的回答,儘管這更像是檢查一切是否「插入」,可以這麼說。我所面對的'詭計'是由南方的orm提供的'實例',例如orm ['contenttypes.contenttype'] .objects.get(pk = 1)!= ContentType.objects.get(pk = 1) - 至少當用作參數來創建另一個模型實例時,比如上面的Publishing。它的奇怪,但它讓我卡住了。 – Daryl 2011-06-03 00:04:39

+0

這確實是一個奇怪的。你使用的所有東西都必須來自南方ORM,但一旦滿足條件,一切都應該正常工作。我曾經在試圖導入一些外部模型時纔看到特定的錯誤,並使用它來代替凍結並通過ORM。也許你應該聯繫南隊;你可能會偶然發現一些錯誤。 – 2011-06-03 14:24:55

+0

謝謝@chrispratt,我向南提出了一個問題http://south.aeracode.org/ticket/781 – Daryl 2011-06-06 00:14:04