You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create and run migration (table and column is created. Notice that in database only 1 constraint is created, which is PK for some_uuid_field column, which is obviously expected behavior)
On model modify unique=True -> unique=False.
Generate migration (notice that we have drop unique constraint step)
Run migration (causes error on trying to drop constraint that doesn't exist as it was not created in first place)
Solution:
When creating a pk column validate if passed arguments contain both pk and unique set to True. If so, then when generating migration for column creation squash unique value as pk is already set to True.
If both values are set to True, in migration create both constraints (doesn't make sense as we already would try to have column to be a pk which should imply being unique)
The text was updated successfully, but these errors were encountered:
Problem described causes errors when running migrations and modifying piccolo models because of missing constraint in database (postgres 17).
Tl;tr
Modifying unique argument on a column causes migration to generate dropping constraint that was not created in the first place.
Recreate steps:
primary_key = True
andunique = True
e.g.
some_uuid_field = UUID(
default=UUID4(),
null=False,
primary_key=True,
unique=True,
index=True,
index_method=IndexMethod.btree,
db_column_name=None,
secret=False,
)
unique=True
->unique=False
.Solution:
The text was updated successfully, but these errors were encountered: