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

On mssql, changing the nullable flag for a Boolean column will create another Check constraint #62

sqlalchemy-bot opened this issue Jul 27, 2012 · 2 comments
bug Something isn't working low priority


Copy link

Migrated issue, originally created by Sok Ann Yap (@sayap)

Here's a sample script:

import sqlalchemy as sa

from alembic import op

tests = sa.sql.table(
    sa.sql.column('col', sa.Boolean()),

def upgrade():
    op.add_column('tests', sa.Column('col', sa.Boolean()))

    op.execute(tests.update().values({'col': False}))

    op.alter_column('tests', 'col',
        type_=sa.Boolean(), nullable=False)

def downgrade():
    op.drop_column('tests', 'col', mssql_drop_check=True)

The downgrade function will fail, as the mssql_drop_check flag only expects one check constraint, but there are two of them now.

Copy link

Michael Bayer (@zzzeek) wrote:

this seems like user error, "type_" means you want to change the type of the column to "boolean". If you want to change just nullability, you send the type along using "existing_type". "existing_type" is of course only needed because DB's like MSSQL and MySQL don't have proper ALTER commands.

However, I tried out "existing_type" and that seems to have a bug, in that it wants to drop the constraint. So the logic to drop/create constraints given types is refined in [[|50c7551d280fdaa099f15427b1627940181594f8]] to include that the constraint is dropped only if existing_type and type_ is given, and additionally no constraints are impacted at all on dialects that don't need these constraints such as postgresql.

Copy link

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

@sqlalchemy-bot sqlalchemy-bot added low priority bug Something isn't working labels Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
bug Something isn't working low priority
None yet

No branches or pull requests

1 participant