gpt4 book ai didi

使用 Postgres BDR 9.4.1 迁移 Django 1.8

转载 作者:行者123 更新时间:2023-11-29 11:31:38 25 4
gpt4 key购买 nike

我正在尝试使用 BDR 在 Postgres 数据库上运行 Django 迁移。

python manage.py makemigrations

工作正常,但正在运行

python manage.py 迁移

导致以下错误:

ALTER TABLE … ALTER COLUMN TYPE … 可能只在 BDR 处于事件状态时影响 UNLOGGED 或 TEMPORARY 表; auth_permission 是一个普通表

有问题的模块是 django/django/contrib/auth/migrations/0002_alter_permission_name_max_length.py

我没有找到任何关于如何使用 Django UNLOGGED 表的信息,尤其是因为 auth_permissions 是一个 Django 表(不是我创建的)。我也不确定 UNLOGGED 表是否会复制。

有人有什么建议吗?

最佳答案

为了使用 BDR 进行迁移,您需要手动创建迁移,仅使用“安全”操作,因为 BDR 目前无法复制迁移中的操作。

在我最近与 2nd Quadrant(BDR 开发的主要赞助商)的支持人员进行的电子邮件对话中,我获得了有关该主题的以下信息:

There is no timeline in delivering this. It's very hard to accomplish.

You can still alter a column's type, it just takes multiple steps. In general, you do DDL in BDR as if you were doing it with a lock-avoidance approach in stock PostgreSQL. So in this case you:

  • ADD the new column without a DEFAULT and without any NOT NULL, and commit. If needed, also create a trigger to automatically fill the new column when values are inserted. Or ALTER the new column to set a DEFAULT, if that's more appropriate.
  • UPDATE the table to copy values to the new column with new type
  • ALTER the table to make it NOT NULL if appropriate
  • DROP the old column

我还找到了this article from BrainTree对于什么可以被认为是“安全”操作,以及您必须如何重写迁移中的行为,这是一个很好的引用。

关于使用 Postgres BDR 9.4.1 迁移 Django 1.8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32748630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com