升级 1.4 -> 1.7 时无法迁移 Django 代理模型
Django proxy model cannot be migrated when upgrading 1.4 -> 1.7
有如下模型
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
都读完了
- https://docs.djangoproject.com/en/1.8/topics/migrations/#dependencies
- https://docs.djangoproject.com/en/1.8/topics/db/models/#proxy-models
我不知道我应该做什么来解决这个问题(manage.py makemigrations
报告 No changes detected
)
问题可以通过 运行 tox -e py27-django17
使用 this github repo
重现
这可以用 Django 1.7 和 1.8 重现,但在 1.4 中可以正常工作
运行manage.py makemigrations <app_label>
。如果迁移文件夹不存在,Django 将不会创建它,除非您明确指定应用程序标签。那是因为(仍然)支持没有迁移的应用程序。
如果 migrations
文件夹存在于应用程序中,并且有一个 __init__.py
文件(即使在 Python 3 上),Django 将把该应用程序作为迁移的应用程序,并且仅使用 manage.py makemigrations
创建迁移。
有如下模型
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
都读完了
- https://docs.djangoproject.com/en/1.8/topics/migrations/#dependencies
- https://docs.djangoproject.com/en/1.8/topics/db/models/#proxy-models
我不知道我应该做什么来解决这个问题(manage.py makemigrations
报告 No changes detected
)
问题可以通过 运行 tox -e py27-django17
使用 this github repo
这可以用 Django 1.7 和 1.8 重现,但在 1.4 中可以正常工作
运行manage.py makemigrations <app_label>
。如果迁移文件夹不存在,Django 将不会创建它,除非您明确指定应用程序标签。那是因为(仍然)支持没有迁移的应用程序。
如果 migrations
文件夹存在于应用程序中,并且有一个 __init__.py
文件(即使在 Python 3 上),Django 将把该应用程序作为迁移的应用程序,并且仅使用 manage.py makemigrations
创建迁移。