Skip to content

Commit

Permalink
Fix the unique constraint migration
Browse files Browse the repository at this point in the history
As the unique constrain is created on index and not on column we need to
remove the index first and recreate it without the unique constrain.

Signed-off-by: Michal Konecny <[email protected]>
  • Loading branch information
Zlopez committed Dec 12, 2024
1 parent 083ffa2 commit 274b5ad
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
def upgrade():
"""Alembic migration."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint("ix_users_username", "users", type_="unique")
# Remove the index and recreate it as there is no way to remove just the unique
# constrain from index
op.drop_index("ix_users_username", "users")
op.create_index("ix_users_username", "users", ["username"])
# ### end Alembic commands ###


def downgrade():
"""Downgrade migration."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_unique_constraint("ix_users_username", "users", ["username"])
op.drop_index("ix_users_username", "users")
op.create_index(op.f("ix_users_username"), "users", ["username"], unique=True)
# ### end Alembic commands ###

0 comments on commit 274b5ad

Please sign in to comment.