)
)
- def add_constraint(self, const: Any) -> None:
+ def add_constraint(self, const: Any, **kw: Any) -> None:
if const._create_rule is None or const._create_rule(self):
- self._exec(schema.AddConstraint(const))
+ if sqla_compat.sqla_2_1:
+ kw.setdefault("isolate_from_table", True)
+ self._exec(schema.AddConstraint(const, **kw))
def drop_constraint(self, const: Constraint, **kw: Any) -> None:
+ if sqla_compat.sqla_2_1:
+ kw.setdefault("isolate_from_table", True)
self._exec(schema.DropConstraint(const, **kw))
def rename_table(
else:
return False
- def add_constraint(self, const: Constraint):
+ def add_constraint(self, const: Constraint, **kw: Any):
# attempt to distinguish between an
# auto-gen constraint and an explicit one
if const._create_rule is None:
--- /dev/null
+.. change::
+ :tags: usecase
+
+ Avoid deprecation warning in add/drop constraint added in SQLAlchemy 2.1.
+ Ensure that alembic is compatible with the changes added in
+ https://github.com/sqlalchemy/sqlalchemy/issues/13006
+ by explicitly setting ``isolate_from_table=True`` when running with
+ SQLAlchemy 2.1 or greater.