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

时间:2021-01-14 20:30:17
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.

I have tried deleting the db and makemigrations and then migrate. Same error

我尝试删除db和makemigrations然后迁移。同样的错误

Then I tried migrate contenttypes before migrate. No change in the traceback.

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

What's wrong?

I'm using django==1.8

我正在使用django == 1.8

2 个解决方案

#1


0  

I just faced the same error message. In my case it was after I injected additional fields into the Django group model. Maybe you do something similiar. The problem is that the auth migration created for the modified Group model is in the pip package folder of Django.

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

I found it in:

我发现它:

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

You could add it as dependency to the failing migration:

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

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

But it would fail when re-building the env from scratch. So this is not a solution :-/.

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

#2


0  

In my case this was related with https://code.djangoproject.com/ticket/25100 bug. For some reason, contenttypes.0002_remove_content_type_name migration was not executed, bet marked as executed. To fix that, I just removed name field manually using this query:

在我的情况下,这与https://code.djangoproject.com/ticket/25100错误有关。由于某种原因,没有执行contenttypes.0002_remove_content_type_name迁移,标记为已执行。为了解决这个问题,我只是使用此查询手动删除了名称字段:

alter table django_content_type drop column name;

After that, migrations started to work.

之后,迁移开始起作用。

#1


0  

I just faced the same error message. In my case it was after I injected additional fields into the Django group model. Maybe you do something similiar. The problem is that the auth migration created for the modified Group model is in the pip package folder of Django.

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

I found it in:

我发现它:

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

You could add it as dependency to the failing migration:

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

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

But it would fail when re-building the env from scratch. So this is not a solution :-/.

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

#2


0  

In my case this was related with https://code.djangoproject.com/ticket/25100 bug. For some reason, contenttypes.0002_remove_content_type_name migration was not executed, bet marked as executed. To fix that, I just removed name field manually using this query:

在我的情况下,这与https://code.djangoproject.com/ticket/25100错误有关。由于某种原因,没有执行contenttypes.0002_remove_content_type_name迁移,标记为已执行。为了解决这个问题,我只是使用此查询手动删除了名称字段:

alter table django_content_type drop column name;

After that, migrations started to work.

之后,迁移开始起作用。