My migrations are not picking up the constraint names? #1194
-
SQLAlchemy 2.0, Python 3.11, Alembic 1.10. In my target_metadata = SQLModel.metadata
target_metadata.naming_convention = {
"ix": "ix_%(column_0_label)s",
"uq": "uq_%(table_name)s_%(column_0_N_name)s",
"ck": "ck_%(table_name)s_%(constraint_name)s",
"fk": "fk_%(table_name)s_%(column_0_N_name)s_%(referred_table_name)s",
"pk": "pk_%(table_name)s_%(column_0_N_name)s",
} ... but when I # stuff elided
op.create_table('models',
sa.Column('model_name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('description', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.PrimaryKeyConstraint('model_name'),
schema='model_cache',
)
# more stuff elided I was expecting that PrimaryKeyConstraint to get a name, as defined in the TIA! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
i believe that .naming_convention has to be there before the Table objects associated with the MetaData get set up. As you build Table objects etc., the naming convention applies symbols to the "name" fields of all the Constraint objects that are what cause the names to happen. this is why SQLAlchemy docs illustrate .naming_convention only set up as a constructor keyword argument on |
Beta Was this translation helpful? Give feedback.
i believe that .naming_convention has to be there before the Table objects associated with the MetaData get set up. As you build Table objects etc., the naming convention applies symbols to the "name" fields of all the Constraint objects that are what cause the names to happen.
this is why SQLAlchemy docs illustrate .naming_convention only set up as a constructor keyword argument on
MetaData
. It has never been tested by just adding the convention after the fact like that (though should work as long as the Table objects are created after it's present).