use batch-operations automaticly when using a sqlite3 database

Issue #316 resolved
Christian Buhtz
created an issue

I am new to alembic so maybe I missunderstand something. I know that sqlite3 doesn't offer a ALTER TABLE and that is why there is the batch-Operation in alembic. Nice.

I tried the auto-migration described in the tutorial. In that situation alembic doesn't detected that a sqlite3 database is used. That info could be simply found in the alembic.ini file.

Running alembic revision --autogenerate work without errors and generate that (snipped) code:

from alembic import op
def upgrade():
    op.drop_column('TrainingUnit', 'foobar')

But running alembic upgrade head causes an error (in my opinion) because sqlite doesn't support ALTER TABLE.

The snipped error messages:

  File "/usr/local/lib/python3.4/dist-packages/alembic/operations/toimpl.py", line 81, in drop_column
    **operation.kw
  File "/usr/local/lib/python3.4/dist-packages/alembic/ddl/impl.py", line 178, in drop_column
    self._exec(base.DropColumn(table_name, column, schema=schema))
  File "/usr/local/lib/python3.4/dist-packages/alembic/ddl/impl.py", line 121, in _exec
    return conn.execute(construct, *multiparams, **params)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/engine/base.py", line 914, in execute
    return meth(self, multiparams, params)
 ..
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/engine/default.py", line 450, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) near "DROP": syntax error [SQL: 'ALTER TABLE "TrainingUnit" DROP COLUMN foobar']

Is my observation correct that alembic doesn't deteced the use of an sqlite-database and that is why it doesn't generate code with the batch-Operation?

If so: This is a feauter request to implement it.

Comments (6)

  1. Michael Bayer repo owner

    im sorry, link where to what exactly? I'd imagine you want a link to "Batch mode" within the main "autogenerate" docs, e.g. people who aren't familiar with batch mode in the first place. if you're already reading the "batch mode" docs, the "autogenerate" feature is an entire topic in the left hand contents.

  2. Log in to comment