【问题标题】:Django proxy model cannot be migrated when upgrading 1.4 -> 1.7升级 1.4 -> 1.7 时无法迁移 Django 代理模型
【发布时间】:2015-07-21 20:24:28
【问题描述】:

有一个像下面这样的模型

from django.contrib.auth.models import User # has migrations in 1.7

class MyProxyUser(User):
    class Meta:
        proxy = True

在没有迁移的应用中运行测试时会出现以下错误:

django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<ModelState: 'django_proxy_model_problems.MyProxyUser'>]
This can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)
 in an app with no migrations; see https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies for more

都读过

我不知道应该怎么做才能解决这个问题(manage.py makemigrations 报告No changes detected

可以通过使用this github repo 运行tox -e py27-django17 来重现该问题

这可以在 Django 1.7 和 1.8 中重现,但在 1.4 中可以正常工作

【问题讨论】:

    标签: django django-models django-migrations


    【解决方案1】:

    运行manage.py makemigrations &lt;app_label&gt;。如果迁移文件夹不存在,Django 不会创建它,除非您明确指定应用标签。这是因为(仍然)支持没有迁移的应用程序。

    如果migrations 文件夹存在于应用程序中,并且有一个__init__.py 文件(即使在Python 3 上),Django 将选择该应用程序作为迁移的应用程序,并仅使用manage.py makemigrations 创建迁移。

    【讨论】:

    • 仅当代理模型是模块中的唯一模型时才有效
    猜你喜欢
    • 2015-12-10
    • 2015-02-23
    • 2014-12-13
    • 2014-12-15
    • 2020-09-29
    • 1970-01-01
    • 2014-10-30
    • 2014-11-25
    • 1970-01-01
    相关资源
    最近更新 更多