I am trying to run Django migrations on a Postgres database with BDR.
python manage.py makemigrations
works fine, but running
python manage.py migrate
results in the following error:
ALTER TABLE … ALTER COLUMN TYPE … may only affect UNLOGGED or TEMPORARY tables when BDR is active; auth_permission is a regular table
The offending module is django/django/contrib/auth/migrations/0002_alter_permission_name_max_length.py
.
I am not finding anything on how to UNLOGGED tables using Django, especially, since auth_permissions is a Django table (not created by me). I am also not sure if UNLOGGED tables will replicate.
Does anyone have any advice?
In order to use migrations with BDR, you would need to create your migrations by hand, using only "safe" operations, because BDR is not currently able to replicate operations such as the one in your migration.
In an email conversation I had recently with support at 2nd Quadrant (the primary sponsors of BDR development), I was given this information on the topic:
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
I also found this article from BrainTree to be a great reference for what could be considered "safe" operations, and how you would have to rewrite the behavior in your migrations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With