Django 1.7 migration cannot find app

China☆狼群 提交于 2019-12-21 17:55:40

问题


I'm creating a data migration for app Notification, in here i'm using the reference of model, Manager, from app accounts

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

It throws error :

    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'

Although from shell i tried something like and it worked

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

Any light on Why is it failing in case of migration ?


回答1:


Your issue is probably already resolved but somebody else might come across this question.

If the Manager model is not in the same app where you are creating the migration you need to add the dependency for the app accounts in the migration. Example:

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


来源:https://stackoverflow.com/questions/31510439/django-1-7-migration-cannot-find-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!