Alembic: How to add unique constraint to existing column

To add, you’d need:
https://alembic.sqlalchemy.org/en/latest/ops.html#alembic.operations.Operations.create_unique_constraint

from alembic import op
op.create_unique_constraint('uq_user_name', 'user', ['name'], schema="my_schema")

To drop, you’d need:
https://alembic.sqlalchemy.org/en/latest/ops.html#alembic.operations.Operations.drop_constraint

op.drop_constraint('uq_user_name', 'user', schema="my_schema")

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)