Skip to content

how alembic reports errors (stack trace, or clean output with a "failed" message, etc) #209

@sqlalchemy-bot

Description

@sqlalchemy-bot

Migrated issue, originally created by Jonathan Herriott (@herriojr)

Edit: See comments for why this was moved to proposal as both cases actually failed.

There are two ways I run alembic, one is where I create a separate test database for my test cases and do the migrations for a set of test cases and then tear them down afterwards. I've run into an issue when doing an alter_column to rename some foreign keys, which work when I run it via command line, but in my tests it fails. Any attempt at fixing this seems to cause the command line to fail. This is all being done with MySQL.

op.alter_column('my_table', 'my_other_table_id', new_column_name='other_table_id')
# This fails when run with alembic.command.upgrade with
#  File "<string>", line 7, in alter_column
#  File "<string>", line 1, in <lambda>
#  File "/opt/virtualenv/tkey/local/lib/python2.7/site-packages/alembic/util.py", line 322, in go
#    return fn(*arg, **kw)
#  File "/opt/virtualenv/tkey/local/lib/python2.7/site-packages/alembic/operations.py", line #300, in alter_column
#    existing_autoincrement=existing_autoincrement
#  File "/opt/virtualenv/tkey/local/lib/python2.7/site-packages/alembic/ddl/mysql.py", line 42, #in alter_column
#    else existing_autoincrement
#  File "/opt/virtualenv/tkey/local/lib/python2.7/site-packages/alembic/ddl/mysql.py", line 71, #in __init__
#    "All MySQL ALTER COLUMN operations "
#CommandError: All MySQL ALTER COLUMN operations require the existing type.

So, then I try and follow the suggestions, and do the following:

op.alter_column('my_table', 'my_other_table_id', new_column_name='other_table_id', existing_type=sa.BigInteger, existing_nullable=False)
# This now fails for both my tests and for my command line upgrade
#  File "<string>", line 7, in alter_column
#  File "<string>", line 1, in <lambda>
#  File "/opt/virtualenv/tkey/local/lib/python2.7/site-packages/alembic/util.py", line 322, in go
#    return fn(*arg, **kw)
#  File "/opt/virtualenv/tkey/local/lib/python2.7/site-packages/alembic/operations.py", line #300, in alter_column
#    existing_autoincrement=existing_autoincrement
#  File "/opt/virtualenv/tkey/local/lib/python2.7/site-packages/alembic/ddl/mysql.py", line 42, #in alter_column
#    else existing_autoincrement
#  File "/opt/virtualenv/tkey/local/lib/python2.7/site-packages/alembic/ddl/impl.py", line 76, in _exec
#    conn.execute(construct, *multiparams, **params)
#  File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 717, in execute
#    return meth(self, multiparams, params)
#  File "build/bdist.linux-x86_64/egg/sqlalchemy/sql/ddl.py", line 67, in #_execute_on_connection
#    return connection._execute_ddl(self, multiparams, params)
#  File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 771, in _execute_ddl
#    compiled
#  File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 927, in #_execute_context
#    context)
#  File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1076, in #_handle_dbapi_exception
#    exc_info
#  File "build/bdist.linux-x86_64/egg/sqlalchemy/util/compat.py", line 185, in #raise_from_cause
#    reraise(type(exception), exception, tb=exc_tb)
#  File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 920, in #_execute_context
#    context)
#  File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/default.py", line 425, in do_execute
#    cursor.execute(statement, parameters)
#  File "/opt/virtualenv/tkey/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
#    self.errorhandler(self, exc, value)
#  File "/opt/virtualenv/tkey/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
#    raise errorclass, errorvalue
#OperationalError: (OperationalError) (1025, "Error on rename of './bc_paas_test/#sql-#377_42' to './bc_paas_test/account_charge' (errno: 150)") 'ALTER TABLE account_charge CHANGE sub_account_plan_id account_plan_id BIGINT NOT NULL' ()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions