-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Postgres sql_alter_enum requires missing 'condition' key #5
Comments
I just realised that ADD VALUE can't work in migrations anyway, not even in RunSQL. The reason is it can't be used inside a transaction and migrations run in a transaction. Per the manual:
So it looks like this needs a more complicated approach. The best hack we could find seems to be coercing the existing enums to text and then dropping and recreating the enum type: https://blog.yo1.dog/updating-enum-values-in-postgresql-the-safe-and-easy-way/ It's not pretty. |
Sorry for the delayed response, been a silly year! The ALTER SQL mismatch on condition seems like a silly oversight, I'll fix that! Thanks The ALTER TYPE in transaction didn't come up in testing for me but could have been a consequence of me not running it in a situation where transactions were forced, so I'll have another look at that. If it is a stopper though, it can be done via forcing non-atomic though, so shouldn't be a complicated fix. :) |
Did you make any headway on this @ashleywaite ? We're currently still working around it by coercing to text and back (including dropping and recreating all constraints). |
Please check this workaround: This change turns this migration:
From this invalid SQL transaction
To this valid SQL transaction
|
When altering an existing enum the SQL format string and dictionary have mismatched signatures, leading to
KeyError 'condition'
when running./manage.py migrate
. Database is PosgreSQL 10:django_enum/patches.py line 77:
sql_alter_enum = 'ALTER TYPE %(enum_type)s ADD VALUE %(value)s %(condition)s'
django_enum/operations.py line 319:
sql = schema_editor.sql_alter_enum % { 'enum_type': self.db_type, 'value': '%s'}
Notice that there is no 'condition' key so the operation fails.
https://www.postgresql.org/docs/9.1/static/sql-altertype.html
So it looks like condition is used to optional set the position of the new enum value but the operation isn't generating or passing the condition.
The text was updated successfully, but these errors were encountered: