创建新内容类型时出错。在尝试单独迁移应用程序之前,请确保已迁移内容类型
Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually
我正在尝试从 Django 1.6
迁移到 Django 1.8
。我在 Django 1.6 中使用 South
来管理 migrations
。 python manage.py makemigrations
我已经成功创建了新的迁移文件。在 运行 python manage.py migrate --fake-initial
时,我收到此错误
Traceback (most recent call last):
File "manage.py", line 39, in <module>
execute_from_command_line(sys.argv)
File "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/site- packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/site- packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/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 "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/site-packages/django/core/management/sql.py", line 280, in emit_post_migrate_signal
using=db)
File "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 201, in send
response = receiver(signal=self, sender=sender, **named)
File "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 82, in create_permissions
ctype = ContentType.objects.db_manager(using).get_for_model(klass)
File "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 78, in get_for_model
"Error creating new content types. Please make sure contenttypes "
其中一个迁移文件 0001_initial.py
说:
dependencies = [
('auth', '0006_require_contenttypes_0002'),
('clients', '0002_auto_20150428_1551'),
('players', '0001_initial'),
]
我想这尤其是问题所在。这个问题的解决方法是什么。任何帮助将不胜感激。
根据this,我认为这与"The removal of ContentType.name
"有关。但不知何故它不起作用。
通过手动从 'django_content_type' table 中删除列 name
。例如。
'ALTER TABLE django_content_type DROP COLUMN name'
我能够应用迁移。也许这至少能让你更进一步。
可能看起来很奇怪,但我通过升级到 Django 版本 1.8 解决了这个问题。
最初我使用的是 ver 1.7
就我而言,我为解决此问题所做的工作是更新到更新版本的 django。
如果你使用 mac 就这样做:
- pip 安装 django --升级
- python manage.py 迁移
- python manage.py 迁移
尝试先迁移 auth 应用程序,然后再迁移其他应用程序:
manage.py migrate auth
manage.py migrate <app_name>
通过@int_ua添加评论
将此作为依赖项添加到失败的迁移中:
dependencies = [
('contenttypes', '0002_remove_content_type_name'),
]
然后运行再次迁移。
我不得不在 Django 1.9.1 中合并两个系统,但我无法克服这个错误:
"Error creating new content types. Please make sure contenttypes "
广泛的谷歌搜索和计算器都没有结果。最后,我将调试行添加到
~/.virtualenvs/(venv_name)/lib/python2.7/site-packages/django/contrib/contenttypes/models.py
except (OperationalError, ProgrammingError, IntegrityError):
# It's possible to migrate a single app before contenttypes,
# as it's not a required initial dependency (it's contrib!)
# Have a nice error for this.
print "\n\nError for Content type model "+opts.model_name+"\n\n"
raise RuntimeError(
"Error creating new content types. Please make sure contenttypes "
"is migrated before trying to migrate apps individually."
)
这告诉我导致错误并最终导致修复的模型名称。
我正在使用 Postgres,tables django_content_type 和 auth_permission 的序列号没有指向 table 的末尾,导致插入失败。
这两行修复了(基于此SO post)
SELECT pg_catalog.setval(pg_get_serial_sequence('django_content_type', 'id'), (SELECT MAX(id) FROM django_content_type)+1);
SELECT pg_catalog.setval(pg_get_serial_sequence('auth_permission', 'id'), (SELECT MAX(id) FROM auth_permission)+1);
我正在尝试从 Django 1.6
迁移到 Django 1.8
。我在 Django 1.6 中使用 South
来管理 migrations
。 python manage.py makemigrations
我已经成功创建了新的迁移文件。在 运行 python manage.py migrate --fake-initial
时,我收到此错误
Traceback (most recent call last):
File "manage.py", line 39, in <module>
execute_from_command_line(sys.argv)
File "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/site- packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/site- packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/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 "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/site-packages/django/core/management/sql.py", line 280, in emit_post_migrate_signal
using=db)
File "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 201, in send
response = receiver(signal=self, sender=sender, **named)
File "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 82, in create_permissions
ctype = ContentType.objects.db_manager(using).get_for_model(klass)
File "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 78, in get_for_model
"Error creating new content types. Please make sure contenttypes "
其中一个迁移文件 0001_initial.py
说:
dependencies = [
('auth', '0006_require_contenttypes_0002'),
('clients', '0002_auto_20150428_1551'),
('players', '0001_initial'),
]
我想这尤其是问题所在。这个问题的解决方法是什么。任何帮助将不胜感激。
根据this,我认为这与"The removal of ContentType.name
"有关。但不知何故它不起作用。
通过手动从 'django_content_type' table 中删除列 name
。例如。
'ALTER TABLE django_content_type DROP COLUMN name'
我能够应用迁移。也许这至少能让你更进一步。
可能看起来很奇怪,但我通过升级到 Django 版本 1.8 解决了这个问题。 最初我使用的是 ver 1.7
就我而言,我为解决此问题所做的工作是更新到更新版本的 django。 如果你使用 mac 就这样做:
- pip 安装 django --升级
- python manage.py 迁移
- python manage.py 迁移
尝试先迁移 auth 应用程序,然后再迁移其他应用程序:
manage.py migrate auth
manage.py migrate <app_name>
通过@int_ua添加评论 将此作为依赖项添加到失败的迁移中:
dependencies = [
('contenttypes', '0002_remove_content_type_name'),
]
然后运行再次迁移。
我不得不在 Django 1.9.1 中合并两个系统,但我无法克服这个错误:
"Error creating new content types. Please make sure contenttypes "
广泛的谷歌搜索和计算器都没有结果。最后,我将调试行添加到
~/.virtualenvs/(venv_name)/lib/python2.7/site-packages/django/contrib/contenttypes/models.py
except (OperationalError, ProgrammingError, IntegrityError):
# It's possible to migrate a single app before contenttypes,
# as it's not a required initial dependency (it's contrib!)
# Have a nice error for this.
print "\n\nError for Content type model "+opts.model_name+"\n\n"
raise RuntimeError(
"Error creating new content types. Please make sure contenttypes "
"is migrated before trying to migrate apps individually."
)
这告诉我导致错误并最终导致修复的模型名称。
我正在使用 Postgres,tables django_content_type 和 auth_permission 的序列号没有指向 table 的末尾,导致插入失败。
这两行修复了(基于此SO post)
SELECT pg_catalog.setval(pg_get_serial_sequence('django_content_type', 'id'), (SELECT MAX(id) FROM django_content_type)+1);
SELECT pg_catalog.setval(pg_get_serial_sequence('auth_permission', 'id'), (SELECT MAX(id) FROM auth_permission)+1);