Django 1.7迁移找不到应用 [英] Django 1.7 migration cannot find app

查看:116
本文介绍了Django 1.7迁移找不到应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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")

抛出错误:

    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'

尽管f从rom shell我尝试了类似的方法,并且效果很好

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 ?

推荐答案

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

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

如果Manager模型不在创建迁移的同一应用中,则需要在迁移中为应用帐户添加依赖项。示例:

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'),
        ...,
    ]`
    ...

这篇关于Django 1.7迁移找不到应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆