Closed
Description
Describe the bug
In a batch alter_table, a column is added and a unique_constraint is added. In version 1.6.5, this worked as expected, but the recent 1.7.0 update now gives:
"NotImplementedError: No support for ALTER of constraints in SQLite dialectPlease refer to the batch mode feature which allows for SQLite migrations using a copy-and-move strategy."
Expected behavior
I believe it is related to the recent change here: e34f6c1
I don't believe any changes to the migration are necessary based on the documented behavior changes that commit suggested.
To Reproduce
with op.batch_alter_table("table") as batch_op:
batch_op.add_column(sa.Column("a", sa.String(length=20), nullable=True))
batch_op.create_unique_constraint(
"uq", ["a", "b"]
)
Error
alembic/versions/391853fcf800_connector_slug.py:22: in upgrade
batch_op.create_unique_constraint(
/usr/lib/python3.8/contextlib.py:120: in __exit__
next(self.gen)
../../../.cache/pypoetry/virtualenvs/app-db-PYu9--OD-py3.8/lib/python3.8/site-packages/alembic/operations/base.py:369: in batch_alter_table
impl.flush()
../../../.cache/pypoetry/virtualenvs/app-db-PYu9--OD-py3.8/lib/python3.8/site-packages/alembic/operations/batch.py:107: in flush
fn(*arg, **kw)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <alembic.ddl.sqlite.SQLiteImpl object at 0x7f3046e44e20>, const = UniqueConstraint(Column('name_slug', NullType(), table=<connector>), Column('org_id', NullType(), table=<connector>))
def add_constraint(self, const: "Constraint"):
# attempt to distinguish between an
# auto-gen constraint and an explicit one
if const._create_rule is None: # type:ignore[attr-defined]
> raise NotImplementedError(
"No support for ALTER of constraints in SQLite dialect"
"Please refer to the batch mode feature which allows for "
"SQLite migrations using a copy-and-move strategy."
E NotImplementedError: No support for ALTER of constraints in SQLite dialectPlease refer to the batch mode feature which allows for SQLite migrations using a copy-and-move strategy.
Versions.
- OS: Ubuntu 20.04.2
- Python: 3.8
- Alembic: 1.7.0
- SQLAlchemy: 1.3.24
- Database: sqlite
Additional context
Have a nice day!