RuntimeError:创建新内容类型时出错

时间:2015-09-18 16:41:00

标签: python django python-2.7 traceback

Operations to perform:
  Synchronize unmigrated apps: google, staticfiles, twitter, messages, reflect, allauth, facebook, rest_framework, crispy_forms
  Apply all migrations: account, django_comments, links, sessions, admin, fluent_comments, sites, auth, contenttypes, socialaccount
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
  Installing custom SQL...
Running migrations:
  No migrations to apply.
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\Home\venv\lib\site-packages\django\core\management\__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "C:\Users\Home\venv\lib\site-packages\django\core\management\__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\Home\venv\lib\site-packages\django\core\management\base.py", line 390, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\Home\venv\lib\site-packages\django\core\management\base.py", line 441, in execute
    output = self.handle(*args, **options)
  File "C:\Users\Home\venv\lib\site-packages\django\core\management\commands\migrate.py", line 225, in handle
    emit_post_migrate_signal(created_models, self.verbosity, self.interactive, connection.alias)
  File "C:\Users\Home\venv\lib\site-packages\django\core\management\sql.py", line 280, in emit_post_migrate_signal
    using=db)
  File "C:\Users\Home\venv\lib\site-packages\django\dispatch\dispatcher.py", line 201, in send
    response = receiver(signal=self, sender=sender, **named)
  File "C:\Users\Home\venv\lib\site-packages\django\contrib\auth\management\__init__.py", line 82, in create_permissions
    ctype = ContentType.objects.db_manager(using).get_for_model(klass)
  File "C:\Users\Home\venv\lib\site-packages\django\contrib\contenttypes\models.py", line 78, in get_for_model
    "Error creating new content types. Please make sure contenttypes "
RuntimeError: Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually.

我尝试删除数据库和makemigrations,然后删除migrate。同样的错误

然后我在migrate contenttypes之前尝试migrate。追溯没有变化。

怎么了?

我正在使用django == 1.8

2 个答案:

答案 0 :(得分:0)

我刚刚遇到了同样的错误消息。在我的情况下,它是在我将另外的字段注入Django组模型之后。也许你做了类似的事情。问题是为修改后的Group模型创建的auth迁移位于Django的pip包文件夹中。

我发现了:

<my_env_folder>/lib/python3.4/site-packages/django/contrib/auth/migrations/0007_auto_20151118_1635.py

您可以将其添加为失败迁移的依赖项:

dependencies = [
    ('auth', '0007_auto_20151118_1635'),
    ('accounts', '0001_admin_user'),
]

但是从头开始重新构建env时会失败。所以这不是解决方案: - /。

答案 1 :(得分:0)

在我的情况下,这与https://code.djangoproject.com/ticket/25100 bug有关。出于某种原因,contenttypes.0002_remove_content_type_name迁移未执行,下注标记为已执行。为了解决这个问题,我刚刚使用此查询手动删除了name字段:

alter table django_content_type drop column name;

之后,迁移开始起作用。