diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-03-05 12:08:16 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-03-05 12:13:08 -0500 |
| commit | 5c4b556c7ae21c82e86cf7b11343cacb4c43cb4a (patch) | |
| tree | 80d239ce2ab27c434c6acec13ab5929f50e6b129 /doc | |
| parent | 837d9640049be78473e2afa360cf9bfbfee91a5c (diff) | |
| download | sqlalchemy-5c4b556c7ae21c82e86cf7b11343cacb4c43cb4a.tar.gz | |
Add a note that the truncation logic also raises an exception for
too-long names.
Change-Id: I8291a56235171827f5c41361b74118ba9c28c4c5
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/build/changelog/migration_13.rst | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/doc/build/changelog/migration_13.rst b/doc/build/changelog/migration_13.rst index f08c59405..15e67fdd5 100644 --- a/doc/build/changelog/migration_13.rst +++ b/doc/build/changelog/migration_13.rst @@ -1059,6 +1059,54 @@ The above suffix ``a79e`` is based on the md5 hash of the long name and will generate the same value every time to produce consistent names for a given schema. +Note that the truncation logic also raises :class:`.IdentifierError` when a +constraint name is explicitly too large for a given dialect. This has been +the behavior for an :class:`.Index` object for a long time, but is now applied +to other kinds of constraints as well:: + + from sqlalchemy import Column + from sqlalchemy import Integer + from sqlalchemy import MetaData + from sqlalchemy import Table + from sqlalchemy import UniqueConstraint + from sqlalchemy.dialects import postgresql + from sqlalchemy.schema import AddConstraint + + m = MetaData() + t = Table("t", m, Column("x", Integer)) + uq = UniqueConstraint( + t.c.x, + name="this_is_too_long_of_a_name_for_any_database_backend_even_postgresql", + ) + + print(AddConstraint(uq).compile(dialect=postgresql.dialect())) + +will output:: + + sqlalchemy.exc.IdentifierError: Identifier + 'this_is_too_long_of_a_name_for_any_database_backend_even_postgresql' + exceeds maximum length of 63 characters + +The exception raise prevents the production of non-deterministic constraint +names truncated by the database backend which are then not compatible with +database migrations later on. + +To apply SQLAlchemy-side truncation rules to the above identifier, use the +:func:`.conv` construct:: + + uq = UniqueConstraint( + t.c.x, + name=conv("this_is_too_long_of_a_name_for_any_database_backend_even_postgresql"), + ) + +This will again output deterministically truncated SQL as in:: + + ALTER TABLE t ADD CONSTRAINT this_is_too_long_of_a_name_for_any_database_backend_eve_ac05 UNIQUE (x) + +There is not at the moment an option to have the names pass through to allow +database-side truncation. This has already been the case for :class:`.Index` +names for some time and issues have not been raised. + The change also repairs two other issues. One is that the ``column_0_key`` token wasn't available even though this token was documented, the other was that the ``referred_column_0_name`` token would inadvertently render the |
