姜戈"ValueErrror: could not find common ancestor of {migrations}"



我正在尝试关注https://docs.djangoproject.com/en/2.0/ref/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')]

我的"心理模型"是,由于Django从dependencies推断迁移的顺序,并且该迁移的顺序没有,因此应该首先运行。但是,当我尝试运行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类中

我想您想在第一个生成的迁移之前运行此迁移。

如果您现在只需要Hstore,而不需要首先运行它,您就可以轻松地将数据迁移到适当的位置。

我最终解决了较大的问题,即使用Hstorefield不必在数据库上手动运行CREATE EXTENSION hstore;,通过将HStoreExtension()操作添加到0001_initial.py迁移的operations;另请参见https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/postgres/postgres/#create-postgresql-extensions.

i首先删除所有迁移文件夹,不起作用,然后我删除虚拟环境,创建新的VENV,再次安装所有软件包 - 这解决了问题(我可以成功地运行迁移和并运行迁移,没有再次显示错误(。这样的东西:
来源env/bin/Activate
pip冻结&gt;需求.txt
PIP卸载-r sumpliont.txt -y n
停用
RM -R env/
Python3 -M Venv env
来源env/bin/Activate
pip install -r sumpliont.txt

最新更新