How to define CheckConstraint properly for autogenerate? #1841
Unanswered
ziima
asked this question in
Usage Questions
Replies: 1 comment 3 replies
|
Hi, I think you may have found a bug in sqlalchemy or at the very least in the implementation of check constraint autogenerate in alembic: import sqlalchemy as sa
t = sa.Table(
"foo",
sa.MetaData(),
sa.Column("id", sa.Integer, sa.CheckConstraint("id > 0", name="bar")),
sa.Column("name", sa.String(50)),
)
print(sa.schema.CreateTable(t))
print(t.constraints)yelds: @zzzeek do you remember the rationale for not registering the constraint on the table in sqlalchemy mike? CheckConstraint is a schema idem so its use in a column should be valid. |
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
With alembic 1.19.0 I discovered a number of
remove_constraintoperations detected in alembic check output. I looked around a bit and I discovered all are caused by theCheckConstraints defined as part of a column.E.g. having model as
alembic checkgeneratesThe part
Column('x', Integer()is a literal output, despite all my constraints areTEXTorUUIDfields and none of the field is namedx.alembic checkworks fine, if I move theCheckConstraintto__table_args__with no other changes.Do I define the
CheckConstraintincorrectly and am I required to define them only at__table_args__or is that a bug in autogeneration?All reactions