姜戈 "ValueErrror: could not find common ancestor of {migrations}"
Django "ValueErrror: could not find common ancestor of {migrations}"
我正在尝试按照 https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/operations/ 中的文档创建迁移,该迁移实际上将在数据库上执行 SQL 语句 CREATE EXTENSION IF NOT EXISTS hstore;
。我已尝试将以下名为 create_extension_hstore.py
的文件添加到 migrations
目录:
from django.db import migrations
from django.contrib.postgres.operations import CreateExtension
class Migration(migrations.Migration):
operations = [CreateExtension(name='hstore')]
我的 'mental model' 是因为 Django 从它们的 dependencies
推断迁移的顺序,而这个有 none,它应该是 运行 第一。但是,当我尝试 运行 python manage.py makemigrations --merge
:
时出现错误
(venv) Kurts-MacBook-Pro:lucy-web kurtpeek$ python manage.py makemigrations --merge
(0.000) SELECT typarray FROM pg_type WHERE typname = 'citext'; args=None
(0.003)
SELECT c.relname, c.relkind
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r', 'v')
AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
AND pg_catalog.pg_table_is_visible(c.oid); args=None
(0.001) SELECT "django_migrations"."app", "django_migrations"."name" FROM "django_migrations"; args=()
Traceback (most recent call last):
File "manage.py", line 29, in <module>
execute_from_command_line(sys.argv)
File "/Users/kurtpeek/Documents/Dev/lucy/lucy-web/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Users/kurtpeek/Documents/Dev/lucy/lucy-web/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/kurtpeek/Documents/Dev/lucy/lucy-web/venv/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/kurtpeek/Documents/Dev/lucy/lucy-web/venv/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/Users/kurtpeek/Documents/Dev/lucy/lucy-web/venv/lib/python3.6/site-packages/django/core/management/commands/makemigrations.py", line 142, in handle
return self.handle_merge(loader, conflicts)
File "/Users/kurtpeek/Documents/Dev/lucy/lucy-web/venv/lib/python3.6/site-packages/django/core/management/commands/makemigrations.py", line 272, in handle_merge
raise ValueError("Could not find common ancestor of %s" % migration_names)
ValueError: Could not find common ancestor of {'0091_family_adopting_or_surrogate', 'create_extension_hstore'}
我该如何解决这个问题?我可以尝试将 dependencies=['0001_initial']
添加到 Migration
class 但这似乎有点武断,因为我真正想要的是 运行 此迁移优先于其他任何事情。
我想你会想要将此迁移添加到 0001 中的依赖项中,如果你想要它 运行 在第一次生成的迁移之前。
如果您现在刚开始需要 hstore 而不需要先 运行 您可以很容易地像平常一样添加 data migration 到位。
我最终使用 HStoreField without having to manually run CREATE EXTENSION hstore;
on the database, by adding the HStoreExtension()
operation to the operations
of the 0001_initial.py
migration; see also https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/operations/#create-postgresql-extensions.
解决了更大的问题
我正在尝试按照 https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/operations/ 中的文档创建迁移,该迁移实际上将在数据库上执行 SQL 语句 CREATE EXTENSION IF NOT EXISTS hstore;
。我已尝试将以下名为 create_extension_hstore.py
的文件添加到 migrations
目录:
from django.db import migrations
from django.contrib.postgres.operations import CreateExtension
class Migration(migrations.Migration):
operations = [CreateExtension(name='hstore')]
我的 'mental model' 是因为 Django 从它们的 dependencies
推断迁移的顺序,而这个有 none,它应该是 运行 第一。但是,当我尝试 运行 python manage.py makemigrations --merge
:
(venv) Kurts-MacBook-Pro:lucy-web kurtpeek$ python manage.py makemigrations --merge
(0.000) SELECT typarray FROM pg_type WHERE typname = 'citext'; args=None
(0.003)
SELECT c.relname, c.relkind
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r', 'v')
AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
AND pg_catalog.pg_table_is_visible(c.oid); args=None
(0.001) SELECT "django_migrations"."app", "django_migrations"."name" FROM "django_migrations"; args=()
Traceback (most recent call last):
File "manage.py", line 29, in <module>
execute_from_command_line(sys.argv)
File "/Users/kurtpeek/Documents/Dev/lucy/lucy-web/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Users/kurtpeek/Documents/Dev/lucy/lucy-web/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/kurtpeek/Documents/Dev/lucy/lucy-web/venv/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/kurtpeek/Documents/Dev/lucy/lucy-web/venv/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/Users/kurtpeek/Documents/Dev/lucy/lucy-web/venv/lib/python3.6/site-packages/django/core/management/commands/makemigrations.py", line 142, in handle
return self.handle_merge(loader, conflicts)
File "/Users/kurtpeek/Documents/Dev/lucy/lucy-web/venv/lib/python3.6/site-packages/django/core/management/commands/makemigrations.py", line 272, in handle_merge
raise ValueError("Could not find common ancestor of %s" % migration_names)
ValueError: Could not find common ancestor of {'0091_family_adopting_or_surrogate', 'create_extension_hstore'}
我该如何解决这个问题?我可以尝试将 dependencies=['0001_initial']
添加到 Migration
class 但这似乎有点武断,因为我真正想要的是 运行 此迁移优先于其他任何事情。
我想你会想要将此迁移添加到 0001 中的依赖项中,如果你想要它 运行 在第一次生成的迁移之前。
如果您现在刚开始需要 hstore 而不需要先 运行 您可以很容易地像平常一样添加 data migration 到位。
我最终使用 HStoreField without having to manually run CREATE EXTENSION hstore;
on the database, by adding the HStoreExtension()
operation to the operations
of the 0001_initial.py
migration; see also https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/operations/#create-postgresql-extensions.