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

render inline CHECK constraint for ADD COLUMN on sqlite #98

Closed
sqlalchemy-bot opened this Issue Jan 10, 2013 · 5 comments

Comments

Projects
None yet
2 participants
@sqlalchemy-bot

sqlalchemy-bot commented Jan 10, 2013

Migrated issue, originally created by Márcio Moreira (@arqeco)

Friends,

I´ve tried without success to add a boolean column to a sqlite file.

File "C:\Python27\lib\site-packages\sqlalchemy\engine\default.py", line 331, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (OperationalError) near "CHECK": syntax error u'ALTER TABLE movimentos ADD CHECK (abc IN (0, 1))' ()

The only way it worked was changing

def upgrade():
    op.add_column('movimentos', sa.Column('abc', sa.Boolean))

to

def upgrade():
    op.add_column('movimentos', sa.Column('abc', sa.Boolean(create_constraint=False) ))

I am new to sqlalchemy and databases in general. Is it the create_constraint=False mandatory for Sqlite databases in alembic?

Greetings,
Márcio

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Jan 10, 2013

Michael Bayer (@zzzeek) wrote:

I'd say you've had success as just using that flag allows it to skip that part of SQLite ALTER which is not supported. Until 0.4.2 comes out that is the workaround.

SQLite has very little support for ALTER and schema migrations. In this case, SQLAlchemy itself doesn't support the column-inline CHECK syntax SQLite is requiring, so for now the CHECK constraint is skipped in b3bc2d8.

This ticket needs to stay open because theoretically we can support the addition of the CHECK constraint as well but SQLAlchemy itself would need some changes to handle this.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Jan 10, 2013

Changes by Michael Bayer (@zzzeek):

  • changed title from "Unable to add boolean column" to "render inline CHECK constraint for ADD COLUMN on s"
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Jun 7, 2013

Changes by Michael Bayer (@zzzeek):

  • added labels: external SQLAlchemy issues
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Nov 27, 2017

Michael Bayer (@zzzeek) wrote:

this should be handled by batch migrations

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Nov 27, 2017

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment