Skip to content

CHECK constraint not created when passed to add_column #655

@trvrmcs

Description

@trvrmcs

Given the following revision script:

from alembic import op
import sqlalchemy as sa

revision = "bug_demo"
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    op.create_table("foo", sa.Column("col1", sa.Integer, sa.CheckConstraint("col1>0")))
    op.add_column("foo", sa.Column("col2", sa.Integer, sa.CheckConstraint("col2>0")))


def downgrade():
    pass

The command alembic upgrade --sql bug_demo produces:

...

CREATE TABLE foo (
    col1 INTEGER CHECK (col1>0)
);

ALTER TABLE foo ADD COLUMN col2 INTEGER;
...

col1 has the check constraint applied, but col2 does not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions