python - Django 迁移命令失败,外键指向用户模型

标签 python django django-models

我在 django 1.7b2 中有一个非常简单的测试应用程序 test_app,它仅包含一个模型:

模型.py

from django.db import models
from django.conf import settings

class TestModel(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL)

当我运行python manage.py makemigrations test_app时,我没有收到任何错误,并且迁移文件已成功创建。但是,当我运行 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

我做错了什么?

最佳答案

这显然是一个已知的错误,正在 django 票证 #22485 中进行跟踪。

关于python - Django 迁移命令失败,外键指向用户模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23345482/

相关文章:

Python 正则表达式否定元字符

javascript - Django:如何从 Django View 中的 ajax 调用中检索序列化的复选框值?

mysql - 将 django 应用程序连接到 drupal 数据库?

python - 如何在 sckikit-learn 中将数据帧列的分类值转换为 one-hot 编码列?

python - 生命计数器不断重置

javascript - Django/Javascript 交互中 POST 无响应

django - OneToOne Model 两种方式删除Cascade

Django 。如何减少每次使用后的优惠券总数

python - Django 模型使用保留 Python 关键字作为数据库列名称

python - 在使用 numpy.genfromtxt 创建的 ndarray 中插入列