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

SQLite offline batch migration fails despite copy_from #289

sqlalchemy-bot opened this issue Mar 27, 2015 · 3 comments

SQLite offline batch migration fails despite copy_from #289

sqlalchemy-bot opened this issue Mar 27, 2015 · 3 comments
batch migrations bug Something isn't working


Copy link

Migrated issue, originally created by Thomas Tanner (@ttanner)

continuing with applied

I have modified the script to define the table and pass it using copy_from
according to the documentation

def upgrade_example():
    sa.Column('uuid', sa.String(length=36), nullable=False),
   with op.batch_alter_table('example', copy_from=Example.__table__) as batch_op:
        batch_op.create_index(batch_op.f('ix_example_uuid'), ['uuid'], unique=True)

"alembic upgrade head --sql" fails with:


INFO  [alembic.env] Migrating database example
INFO  [alembic.env] Writing output to example.sql
INFO  [alembic.migration] Context impl SQLiteImpl.
INFO  [alembic.migration] Generating static SQL
INFO  [alembic.migration] Will assume non-transactional DDL.
INFO  [alembic.migration] Running upgrade  -> initial, empty message
Traceback (most recent call last):
  File "<path>/bin/alembic", line 9, in <module>
    load_entry_point('alembic==0.7.5.post2.dev0', 'console_scripts', 'alembic')()
  File "<path>/lib/python/site-packages/alembic/", line 439, in main
  File "<path>/lib/python/site-packages/alembic/", line 433, in main
    self.run_cmd(cfg, options)
  File "<path>/lib/python/site-packages/alembic/", line 416, in run_cmd
    **dict((k, getattr(options, k)) for k in kwarg)
  File "<path>/lib/python/site-packages/alembic/", line 165, in upgrade
  File "<path>/lib/python/site-packages/alembic/", line 390, in run_env
    util.load_python_file(self.dir, '')
  File "<path>/lib/python/site-packages/alembic/", line 243, in load_python_file
    module = load_module_py(module_id, path)
  File "<path>/lib/python/site-packages/alembic/", line 79, in load_module_py
    mod = imp.load_source(module_id, path, fp)
  File "alembic/", line 171, in <module>
  File "alembic/", line 112, in run_migrations_offline
  File "<string>", line 7, in run_migrations
  File "<path>/lib/python/site-packages/alembic/", line 742, in run_migrations
  File "<path>/lib/python/site-packages/alembic/", line 309, in run_migrations
  File "<proj>/alembic/versions/", line 23, in upgrade
    globals()["upgrade_%s" % engine_name]()
  File "<proj>/alembic/versions/", line 56, in upgrade_example
    batch_op.create_index(batch_op.f('ix_example_uuid'), ['uuid'], unique=True)
  File "<path>/lib/python2.7/", line 24, in __exit__
  File "<path>/lib/python/site-packages/alembic/", line 320, in batch_alter_table
  File "<path>/lib/python/site-packages/alembic/", line 66, in flush
    *self.reflect_args, **self.reflect_kwargs)
  File "<path>/lib/python/site-packages/sqlalchemy/sql/", line 406, in __new__
    table._init(name, metadata, *args, **kw)
  File "<path>/lib/python/site-packages/sqlalchemy/sql/", line 479, in _init
    self._autoload(metadata, autoload_with, include_columns)
  File "<path>/lib/python/site-packages/sqlalchemy/sql/", line 489, in _autoload
AttributeError: 'MockConnection' object has no attribute 'run_callable'

sqlalchemy 0.9.9, alembic 0.7.6 (master), Python 2.7.9

In the alembic source I noticed BatchOperationsImpl.copy_from is not used anywhere.

Copy link

Michael Bayer (@zzzeek) wrote:

  • Fully implemented the
    :paramref:~.Operations.batch_alter_table.copy_from parameter for
    batch mode, which previously was not functioning. This allows
    "batch mode" to be usable in conjunction with --sql.
    fixes SQLite offline batch migration fails despite copy_from #289
  • sqlite dialect checks for "create_index" and "drop_index" as exceptions
    for "recreate" in batch mode, the same way as "add_column", so that
    unnecessary table recreates don't emit for index-only operations


Copy link

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

Copy link

Thomas Tanner (@ttanner) wrote:

Thank you for your excellent work! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
batch migrations bug Something isn't working
None yet

No branches or pull requests

2 participants