Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHECK constraint not created when passed to add_column #655

Closed
trvrmcs opened this issue Feb 6, 2020 · 2 comments
Closed

CHECK constraint not created when passed to add_column #655

trvrmcs opened this issue Feb 6, 2020 · 2 comments
Labels
bug Something isn't working op directives

Comments

@trvrmcs
Copy link

trvrmcs commented Feb 6, 2020

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.

@sqla-tester
Copy link
Collaborator

Mike Bayer has proposed a fix for this issue in the master branch:

Render inline constraints for add_column https://gerrit.sqlalchemy.org/1710

@zzzeek zzzeek added bug Something isn't working op directives labels Feb 6, 2020
@zzzeek
Copy link
Member

zzzeek commented Feb 6, 2020

thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working op directives
Projects
None yet
Development

No branches or pull requests

3 participants