【问题标题】:Django 1.7 migration cannot find appDjango 1.7 迁移找不到应用程序
【发布时间】:2015-10-09 05:14:07
【问题描述】:

我正在为应用程序Notification 创建数据迁移,这里我使用来自应用程序accounts 的模型Manager 的引用

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'

虽然我在 shell 中尝试过类似的方法,但它确实有效

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

任何关于为什么在迁移的情况下会失败?

【问题讨论】:

    标签: django-migrations


    【解决方案1】:

    您的问题可能已经解决,但其他人可能会遇到这个问题。

    如果 Manager 模型不在您创建迁移的同一应用程序中,您需要在迁移中添加应用程序 accounts 的依赖项。示例:

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

    【讨论】:

      猜你喜欢
      • 2014-12-29
      • 2015-04-08
      • 2014-08-21
      • 1970-01-01
      • 2014-12-13
      • 1970-01-01
      • 2015-10-31
      • 2014-05-28
      • 2015-02-09
      相关资源
      最近更新 更多