From: Mike Bayer Date: Wed, 1 Sep 2021 14:57:00 +0000 (-0400) Subject: clarify that only named check constraints are regenerated X-Git-Tag: rel_1_7_2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f0e6474d8d76cb86ce1b5f5bb3d775862df129a;p=thirdparty%2Fsqlalchemy%2Falembic.git clarify that only named check constraints are regenerated Change-Id: Ie0489137122d6ccedfa7c1af44dc8420a0842ee8 References: #400 --- diff --git a/docs/build/batch.rst b/docs/build/batch.rst index 00ccc0f7..7b14a64c 100644 --- a/docs/build/batch.rst +++ b/docs/build/batch.rst @@ -243,11 +243,14 @@ the check constraint also:: recreate operation. For **unnamed** CHECK constraints, these are still not automatically included -as part of the batch process as they are often present due to the use of the +as part of the batch process. Note that this limitation **includes** the CHECK +constraints generated by the :class:`~sqlalchemy.types.Boolean` or :class:`~sqlalchemy.types.Enum` datatypes, which up through SQLAlchemy 1.3 would generate CHECK constraints -automatically and cannot be tracked to the reflected table. Therefore unnamed -constraints can be stated explicitly if they are to be included in the +automatically and cannot be tracked to the reflected table, assuming they are +generated in an unnamed way. + +Unnamed constraints can be stated explicitly if they are to be included in the recreated table:: with op.batch_alter_table("some_table", table_args=[ @@ -256,10 +259,16 @@ recreated table:: batch_op.add_column(Column('foo', Integer)) batch_op.drop_column('bar') -Note this only includes CHECK constraints that are explicitly stated -as part of the table definition, not the CHECK constraints that are generated -by datatypes such as :class:`~sqlalchemy.types.Boolean` or -:class:`~sqlalchemy.types.Enum`. +The above step needs only be taken for CHECK constraints that are explicitly stated +as part of the table definition. + +For CHECK constraints that are generated by datatypes such as +:class:`~sqlalchemy.types.Boolean` or :class:`~sqlalchemy.types.Enum`, the type +objects themselves **must be named** in order for their CHECK constraints to be +included in the batch process. Boolean and Enum datatypes that do not +have the ``.name`` attribute set will **not** have CHECK constraints +regenerated. This name can be set by specifying the ``.name`` parameter +or by using a named Python ``Enum`` object as the source of enumeration. Dealing with Referencing Foreign Keys ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^