2015-09-23 61 views
3

我想在BDR上运行Postgres数据库上的Django迁移。Django 1.8与Postgres BDR迁移9.4.1

python manage.py makemigrations

工作正常,但运行

python manage.py migrate

导致以下错误:

ALTER TABLE … ALTER COLUMN TYPE … may only affect UNLOGGED or TEMPORARY tables when BDR is active; auth_permission is a regular table

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

我没有发现任何关于如何使用Django的UNLOGGED表,特别是auth_permissions是一个Django表(不是由我创建的)。我也不确定UNLOGGED表是否会复制。

有没有人有任何建议?

回答

5

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

在电子邮件会话我在第二象限(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是一个很好的参考为什么可以被认为是“安全”的操作,以及你将如何重写迁移中的行为。

+0

谢谢你,乔伊。这是非常有帮助的,虽然他们还没有支持这些东西。 – keda

+0

同意。然而,正如BrainTree的那篇文章中指出的那样,缺乏支持确实有助于实现高可用性的最佳实践。 –

0

您可以覆盖使用MIGRATION_MODULES设置了AUTH应用内置的迁移,例如:

MIGRATION_MODULES = { 
    'auth': 'bdr_migrations.auth', 
} 

然后迁移文件复制从Django的包/项目/ bdr_migrations/auth /中,并对其进行调整,以匹配BDR限制。