Django多租户迁移提高了KeyError:“ Prune”

发布于 2025-02-05 21:54:09 字数 2231 浏览 2 评论 0原文

因此,我已经在一个项目中工作了一段时间,并且根本没有真正改变模型,因此没有进行任何迁移。现在,我需要添加两个新字段并删除另一个通常,这通常应该很好。我正在使用django-tenants,所以我运行迁移的命令是./ manage.py migrate_schemas。 现在,每当我运行该操作时,我都会获得错误keyError:“ Prune”(下面的完整追溯),似乎是Django的内部代码。

现在,之后,我尝试重新恢复更改,因此没有新的迁移并再次运行Comnad,并遇到了同样的错误。我还认为可能在某个时候数据库变得“肮脏”,所以我尝试从头开始迁移一个干净的数据库,结果相同。迁移甚至没有开始。

有人遇到过类似的事情吗?

完整的追溯(我简化了路径)

[standard:public] === Starting migration
Traceback (most recent call last):
  File ":directory/./manage.py", line 22, in <module>
    main()
  File ":directory/./manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "$venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "$/lib/python3.9/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "$venv/lib/python3.9/site-packages/django/core/management/base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "$venv/lib/python3.9/site-packages/django/core/management/base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "$venv/lib/python3.9/site-packages/django_tenants/management/commands/migrate_schemas.py", line 52, in handle
    executor.run_migrations(tenants=[self.PUBLIC_SCHEMA_NAME])
  File "$venv/lib/python3.9/site-packages/django_tenants/migration_executors/standard.py", line 11, in run_migrations
    run_migrations(self.args, self.options, self.codename, self.PUBLIC_SCHEMA_NAME)
  File "$venv/lib/python3.9/site-packages/django_tenants/migration_executors/base.py", line 53, in run_migrations
    MigrateCommand(stdout=stdout, stderr=stderr).execute(*args, **options)
  File "$venv/lib/python3.9/site-packages/django/core/management/base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "$venv/lib/python3.9/site-packages/django/core/management/base.py", line 96, in wrapped
    res = handle_func(*args, **kwargs)
  File "$venv/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 188, in handle
    if options["prune"]:
KeyError: 'prune'

So I've been working in a project for a while, and haven't really changed the models at all, and therefore haven't done any migrations. Now I needed to add two new fields and delete another one, which should be normally fine. I'm using django-tenants, so my command to run the migrations is ./manage.py migrate_schemas.
Now, whenever I run that, I get the error KeyError: "prune" (the full traceback is below) in what seems to be internal code of Django.

Now, afterwards I tried reverting my changes, so no new migration and running the comnad again, and got the same error. I also thought that maybe the database had gotten "dirty" at some point, so I tried migrating a clean database from scratch, with the same result. The migrations don't even get to start.

Has anyone ever encountered something similar?

The full traceback (I have simplified the paths)

[standard:public] === Starting migration
Traceback (most recent call last):
  File ":directory/./manage.py", line 22, in <module>
    main()
  File ":directory/./manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "$venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "$/lib/python3.9/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "$venv/lib/python3.9/site-packages/django/core/management/base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "$venv/lib/python3.9/site-packages/django/core/management/base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "$venv/lib/python3.9/site-packages/django_tenants/management/commands/migrate_schemas.py", line 52, in handle
    executor.run_migrations(tenants=[self.PUBLIC_SCHEMA_NAME])
  File "$venv/lib/python3.9/site-packages/django_tenants/migration_executors/standard.py", line 11, in run_migrations
    run_migrations(self.args, self.options, self.codename, self.PUBLIC_SCHEMA_NAME)
  File "$venv/lib/python3.9/site-packages/django_tenants/migration_executors/base.py", line 53, in run_migrations
    MigrateCommand(stdout=stdout, stderr=stderr).execute(*args, **options)
  File "$venv/lib/python3.9/site-packages/django/core/management/base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "$venv/lib/python3.9/site-packages/django/core/management/base.py", line 96, in wrapped
    res = handle_func(*args, **kwargs)
  File "$venv/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 188, in handle
    if options["prune"]:
KeyError: 'prune'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尬尬 2025-02-12 21:54:09

似乎版本不兼容。

prune选项 2022年1月22日)

如果要使用新的django,则必须修补django-tenants手动和

def add_arguments(self, parser):
    parser.add_argument(
        '--prune', action='store_true', dest='prune',
        help='Delete nonexistent migrations from the django_migrations table.',
    )

django-tenants/blob/fc4956067fb3a486ae04472374705298f3a47474f6/django_tenants / t查找 evarese prune >,因此您可以创建新的;)

It seems like version incompatibility.

prune option added to Django couple months ago (Jan 22, 2022)

If you want to use newer Django you have to patch django-tenants manually and add --prune argument

def add_arguments(self, parser):
    parser.add_argument(
        '--prune', action='store_true', dest='prune',
        help='Delete nonexistent migrations from the django_migrations table.',
    )

PS I couldn't find issue related to prune, so you may create new one ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文