2015-07-20 87 views
3

我創建的應用程序Notification數據遷移,在這裏我使用的模型,Manager的參考,從應用accounts的Django 1.7遷移無法找到應用程序

Manager = apps.get_model("accounts", "Manager") 

它拋出錯誤:

self.code(from_state.render(), schema_editor) 
    File "/home/notifications/migrations/0004_auto_20150720_0127.py", line 12, in set_notification_setttings 
    Manager = apps.get_model("accounts", "Manager") 
    File "/home/local/lib/python2.7/site-packages/django/apps/registry.py", line 202, in get_model 
    return self.get_app_config(app_label).get_model(model_name.lower()) 
    File "/home/local/lib/python2.7/site-packages/django/apps/registry.py", line 150, in get_app_config 
    raise LookupError("No installed app with label '%s'." % app_label) 
LookupError: No installed app with label 'accounts' 

雖然從殼我想是這樣,它的工作

>> from django.apps import apps 
>> apps.get_app_config('accounts').get_model('Manager'.lower()) 
>> accounts.models.Manager 

任何亮點爲什麼在遷移時失敗?

回答

5

您的問題可能已經解決,但其他人可能會遇到此問題。

如果Manager模型不在創建遷移的同一應用程序中,則需要在遷移中添加應用程序accounts的依賴項。例如:

class Migration(migrations.Migration): 
    dependencies = [ 
     ('Current_App_Name', 'XYZ_Last_Migration_of_App'), 
     ('accounts', '0012_auto_XYZ'), 
     ..., 
    ]` 
    ...