[英]Django migrate command fails with foreign key to user model
I have a very simple test application, test_app, in django 1.7b2 that consists of only one model: 我在Django 1.7b2中有一个非常简单的测试应用程序test_app,它仅包含一个模型:
models.py models.py
from django.db import models
from django.conf import settings
class TestModel(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
When I run python manage.py makemigrations test_app
, I get no errors and the migration file is created successfully. 当我运行
python manage.py makemigrations test_app
,没有任何错误,并且迁移文件已成功创建。 However, when I come to run python manage.py migrate
, I get the following error: 但是,当我运行
python manage.py migrate
,出现以下错误:
Operations to perform:
Synchronize unmigrated apps: admin, contenttypes, auth, sessions
Apply all migrations: test_app, auth
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
Applying test_app.0001_initial...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
427, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
419, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 288,
in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 337,
in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\django\core\management\commands\migrate.py
", line 145, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 60
, in migrate
self.apply_migration(migration, fake=fake)
File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 88
, in apply_migration
if self.detect_soft_applied(migration):
File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 13
2, in detect_soft_applied
apps = project_state.render()
File "C:\Python27\lib\site-packages\django\db\migrations\state.py", line 63, i
n render
model=dangling_lookup[0]))
ValueError: Lookup failed for model referenced by field auth.Permission.content_
type: contenttypes.ContentType
What I am doing wrong? 我做错了什么?
这显然是一个已知的错误,并且在Django票证中已被跟踪#22485
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.