Discussion:
drop unique constraint for sqlite
Pan Luo
2014-12-24 18:40:20 UTC
Permalink
According to the doc
here: http://alembic.readthedocs.org/en/latest/batch.html#including-unnamed-unique-constraints, sqlalchemy
(<1.0) doesn't reflect the unique constraint. So when I drop it, I got:
"ValueError: No such constraint: 'uq_Criteria_name'" error. Here is my
code:

convention = {
"ix": 'ix_%(column_0_label)s',
"uq": "uq_%(table_name)s_%(column_0_name)s",
"ck": "ck_%(table_name)s_%(constraint_name)s",
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
"pk": "pk_%(table_name)s"
}

with op.batch_alter_table('Criteria', naming_convention=convention) as
batch_op:
batch_op.drop_constraint('uq_Criteria_name', type_='unique')

Where 'name' is the column in Criteria table. Did I missing anything? Is
there any way to drop the unique constraint? Thanks.
--
You received this message because you are subscribed to the Google Groups "sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy-alembic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Michael Bayer
2014-12-27 02:24:53 UTC
Permalink
Post by Pan Luo
convention = {
"ix": 'ix_%(column_0_label)s',
"uq": "uq_%(table_name)s_%(column_0_name)s",
"ck": "ck_%(table_name)s_%(constraint_name)s",
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
"pk": "pk_%(table_name)s"
}
batch_op.drop_constraint('uq_Criteria_name', type_='unique')
Where 'name' is the column in Criteria table. Did I missing anything? Is there any way to drop the unique constraint? Thanks.
if the constraint was not created with a name then it’s a little awkward to start using the naming convention feature after the fact.

Also, if you’re only dealing with sqlite, you could just exclude the drop_constraint entirely as SQLAlchemy isn’t picking up on it and the recreate will just skip it.

Otherwise, since an unnamed constraint is not reflected in 0.9 you need to add it manually as shown at http://alembic.readthedocs.org/en/latest/batch.html#including-unnamed-unique-constraints.
--
You received this message because you are subscribed to the Google Groups "sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy-alembic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...