django-migrations - Django 1.7 迁移找不到应用程序

标签 django-migrations

我正在为应用程序创建数据迁移 Notification ,在这里我使用模型的引用,Manager ,来自应用程序 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'

虽然从 shell 我尝试了类似的东西并且它起作用了
>> from django.apps import apps
>> apps.get_app_config('accounts').get_model('Manager'.lower())
>> accounts.models.Manager

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

最佳答案

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

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

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

关于django-migrations - Django 1.7 迁移找不到应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31510439/

相关文章:

python - 带有 uuid 字段的 Django 迁移生成重复值

django - 在 Django 迁移期间收到 "ValueError: Found wrong number (0) of constraints for ..."

python - 如何恢复上次迁移?

Django 1.7 中的 Django-migrations 检测模型更改,但不会将其应用于迁移

python - 在 Django 数据迁移中打印到 stdout 或 stderr 是否可以?如果是这样,如何?

python - Django 数据迁移在运行 manage.py test 时失败,但在运行 manage.py migrate 时失败

python - 出现 Django 迁移错误 "sequence must have same owner as table it is linked to",但所有表和序列都具有相同的所有者

python - 将 Django 模型/类导出到 SQL 语句

django - 如何在 Django 1.7+ 中创建每个项目的 initial_data 固定装置

python - 尽管单元测试正常运行,Authtoken 迁移仍无法正常工作