Hello,

As I try alembic (for the first time), I ran into the following stack 
traces when attempting to conduct a "nasty" migration.

I call it "nasty" because the original model was based on sqlalchemy v0.9 + 
python 2.7 and the new model is sqlalchemy v1.2 + python 3.6. 
ON TOP OF THAT, it's a massive table and model restructuring. Backend is 
postgres.

I am thinking that I can leverage alembic to do the heavy lifting of 
creating/dropping stuff while I can interject my own bulk_inserts and 
bulk_updates and preserve the existing data.  Something like:

// versions/deadbeef_nasty.py

def upgrade():
    op.drop_table(...)
    op.drop_table(...)
    ...

    # Here is where I am planning to add my bulk_inserts and bulk_updates

    op.add_column(...)
    op.drop_column(...)
    ...



*Is this a reasonable approach?*

*With regards to the stack traces, they differ between online (first stack) 
and offline (second). Hence, this post.*
*Does that make sense?*

*Question: are online migrations run within a single transaction or not?*

*Thanks!!!*


$ alembic upgrade head 

/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package 
will be renamed from release 2.8; in order to keep installing from binary 
please use "pip install psycopg2-binary" instead. For details see: 
<http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>. 


 """) 

INFO [alembic.runtime.migration] Context impl PostgresqlImpl. 

INFO [alembic.runtime.migration] Will assume transactional DDL. 

INFO [alembic.runtime.migration] Running upgrade 55ebe08ba589 -> 
b6c3cd0ef4cb, version 1 

Traceback (most recent call last): 

 File "/Users/hp3/.pyenv/versions/server_py2/bin/alembic", line 11, in 
<module> 

 sys.exit(main()) 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/alembic/config.py", line 486, in main 

 CommandLine(prog=prog).main(argv=argv) 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/alembic/config.py", line 480, in main 

 self.run_cmd(cfg, options) 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/alembic/config.py", line 463, in run_cmd 

 **dict((k, getattr(options, k, None)) for k in kwarg) 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/alembic/command.py", line 254, in upgrade 

 script.run_env() 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/alembic/script/base.py", line 427, in run_env 

 util.load_python_file(self.dir, 'env.py') 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/alembic/util/pyfiles.py", line 81, in load_python_file 

 module = load_module_py(module_id, path) 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/alembic/util/compat.py", line 135, in load_module_py 

 mod = imp.load_source(module_id, path, fp) 

 File "alembic/env.py", line 72, in <module> 

 run_migrations_online() 

 File "alembic/env.py", line 67, in run_migrations_online 

 context.run_migrations() 

 File "<string>", line 8, in run_migrations 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/alembic/runtime/environment.py", line 836, in run_migrations 

 self.get_context().run_migrations(**kw) 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/alembic/runtime/migration.py", line 330, in run_migrations 

 step.migration_fn(**kw) 

 File "/Users/hp3/Documents/python_workspace/Plannotate2_Cloud/src/server/
alembic/versions/b6c3cd0ef4cb_version_1.py", line 38, in upgrade 

 op.drop_table('groups_history') 

 File "<string>", line 8, in drop_table 

 File "<string>", line 3, in drop_table 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/alembic/operations/ops.py", line 1187, in drop_table 

 operations.invoke(op) 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/alembic/operations/base.py", line 319, in invoke 

 return fn(self, operation) 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/alembic/operations/toimpl.py", line 70, in drop_table 

 operation.to_table(operations.migration_context) 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/alembic/ddl/impl.py", line 198, in drop_table 

 self._exec(schema.DropTable(table)) 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/alembic/ddl/impl.py", line 115, in _exec 

 return conn.execute(construct, *multiparams, **params) 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/sqlalchemy/engine/base.py", line 729, in execute 

 return meth(self, multiparams, params) 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/sqlalchemy/sql/ddl.py", line 69, in _execute_on_connection 

 return connection._execute_ddl(self, multiparams, params) 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/sqlalchemy/engine/base.py", line 783, in _execute_ddl 

 compiled 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/sqlalchemy/engine/base.py", line 958, in _execute_context 

 context) 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/sqlalchemy/engine/base.py", line 1160, in _handle_dbapi_exception 

 exc_info 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/sqlalchemy/util/compat.py", line 199, in raise_from_cause 

 reraise(type(exception), exception, tb=exc_tb) 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/sqlalchemy/engine/base.py", line 951, in _execute_context 

 context) 

 File "/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-
packages/sqlalchemy/engine/default.py", line 436, in do_execute 

 cursor.execute(statement, parameters)
sqlalchemy.exc.InternalError: (InternalError) cannot drop table 
groups_history because other objects depend on it
DETAIL: constraint folders_history_id_fkey on table folders_history depends 
on table groups_history
constraint projects_history_id_fkey on table projects_history depends on 
table groups_history
constraint userprofiles_history_id_fkey on table userprofiles_history 
depends on table groups_history
HINT: Use DROP ... CASCADE to drop the dependent objects too.









*When I try the same migration "offline" the stack trace looks like this:*




File "/Users/hp3/.pyenv/versions/server_py2/bin/alembic", line 11, in 
<module>

 sys.exit(main())

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/alembic/config.py"
, line 486, in main

 CommandLine(prog=prog).main(argv=argv)

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/alembic/config.py"
, line 480, in main

 self.run_cmd(cfg, options)

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/alembic/config.py"
, line 463, in run_cmd

 **dict((k, getattr(options, k, None)) for k in kwarg)

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/alembic/command.py"
, line 254, in upgrade

 script.run_env()

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/alembic/script/base.py"
, line 427, in run_env

 util.load_python_file(self.dir, 'env.py')

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/alembic/util/pyfiles.py"
, line 81, in load_python_file

 module = load_module_py(module_id, path)

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/alembic/util/compat.py"
, line 135, in load_module_py

 mod = imp.load_source(module_id, path, fp)

 File "alembic/env.py", line 70, in <module>

 run_migrations_offline()

 File "alembic/env.py", line 45, in run_migrations_offline

 context.run_migrations()

 File "<string>", line 8, in run_migrations

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/alembic/runtime/environment.py"
, line 836, in run_migrations

 self.get_context().run_migrations(**kw)

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/alembic/runtime/migration.py"
, line 330, in run_migrations

 step.migration_fn(**kw)

 File 
"/Users/hp3/Documents/python_workspace/Plannotate2_Cloud/src/server/alembic/versions/b6c3cd0ef4cb_version_1.py"
, line 39, in upgrade

 op.drop_index('ix_layers_history_page_id', table_name='layers_history')

 File "<string>", line 8, in drop_index

 File "<string>", line 3, in drop_index

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/alembic/operations/ops.py"
, line 964, in drop_index

 return operations.invoke(op)

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/alembic/operations/base.py"
, line 319, in invoke

 return fn(self, operation)

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/alembic/operations/toimpl.py"
, line 94, in drop_index

 operation.to_index(operations.migration_context)

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/alembic/operations/ops.py"
, line 921, in to_index

 schema=self.schema, **self.kw)

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/alembic/operations/schemaobj.py"
, line 131, in index

 **kw)

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/sqlalchemy/sql/schema.py"
, line 2860, in __init__

 ColumnCollectionMixin.__init__(self, *columns)

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/sqlalchemy/sql/schema.py"
, line 2259, in __init__

 self._set_parent_with_dispatch(self._pending_colargs[0].table)

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/sqlalchemy/sql/base.py"
, line 434, in _set_parent_with_dispatch

 self.dispatch.after_parent_attach(self, parent)

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/sqlalchemy/event/attr.py"
, line 221, in __call__

 fn(*args, **kw)

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/sqlalchemy/sql/naming.py"
, line 142, in _constraint_name

 newname = _constraint_name_for_table(const, table)

 File 
"/Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site-packages/sqlalchemy/sql/naming.py"
, line 118, in _constraint_name_for_table

 "constraint_name" in convention

 

TypeError: argument of type 'instance' is not iterable

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy-alembic+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to