Unable to change column comment with Alembic
See original GitHub issueWe’re using sqlalchemy-redshift with Alembic, and have found that we are unable to add or change comments on columns. Creating a new column with a comment works fine though.
Let me know if there’s any more information I can provide, or if I should open this issue with SQLAlchemy or Alembic.
from alembic import op
op.alter_column(
'some_table',
'some_column',
comment='my column comment',
)
sqlalchemy.exc.CompileError: <class 'alembic.ddl.base.ColumnComment'> construct has no default compilation handler.
click for full traceback
Traceback (most recent call last):
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/sql/visitors.py", line 88, in _compiler_dispatch
meth = getter(visitor)
AttributeError: 'RedshiftDDLCompiler' object has no attribute 'visit_clause'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/ext/compiler.py", line 423, in _wrap_existing_dispatch
return existing_dispatch(element, compiler, **kw)
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/sql/visitors.py", line 90, in _compiler_dispatch
raise exc.UnsupportedCompilationError(visitor, cls)
sqlalchemy.exc.UnsupportedCompilationError: Compiler <sqlalchemy_redshift.dialect.RedshiftDDLCompiler object at 0x7f2436379a20> can't render element of type <class 'sqlalchemy.sql.elements.ClauseElement'> (Background on this error at: http://sqlalche.me/e/l7de)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/elliott/.virtualenvs/dwp/bin/alembic", line 10, in <module>
sys.exit(main())
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/config.py", line 573, in main
CommandLine(prog=prog).main(argv=argv)
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/config.py", line 567, in main
self.run_cmd(cfg, options)
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/config.py", line 547, in run_cmd
**dict((k, getattr(options, k, None)) for k in kwarg)
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/command.py", line 298, in upgrade
script.run_env()
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/script/base.py", line 489, in run_env
util.load_python_file(self.dir, "env.py")
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/util/pyfiles.py", line 98, in load_python_file
module = load_module_py(module_id, path)
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/util/compat.py", line 173, in load_module_py
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "alembic/env.py", line 152, in <module>
run_migrations_online()
File "alembic/env.py", line 146, in run_migrations_online
context.run_migrations()
File "<string>", line 8, in run_migrations
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/runtime/environment.py", line 846, in run_migrations
self.get_context().run_migrations(**kw)
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/runtime/migration.py", line 518, in run_migrations
step.migration_fn(**kw)
File "/home/elliott/dwp/arthur/ltbd/alembic/versions/2020-02-06_60f608383d18_column_comment_test.py", line 24, in upgrade
comment="test comment",
File "<string>", line 8, in alter_column
File "<string>", line 3, in alter_column
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/operations/ops.py", line 1777, in alter_column
return operations.invoke(alt)
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/operations/base.py", line 345, in invoke
return fn(self, operation)
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/operations/toimpl.py", line 56, in alter_column
**operation.kw
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/ddl/postgresql.py", line 140, in alter_column
**kw
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/ddl/impl.py", line 212, in alter_column
existing_comment=existing_comment,
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/ddl/impl.py", line 134, in _exec
return conn.execute(construct, *multiparams, **params)
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 988, in execute
return meth(self, multiparams, params)
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/sql/ddl.py", line 72, in _execute_on_connection
return connection._execute_ddl(self, multiparams, params)
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1043, in _execute_ddl
else None,
File "<string>", line 1, in <lambda>
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/sql/elements.py", line 462, in compile
return self._compiler(dialect, bind=bind, **kw)
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/sql/ddl.py", line 29, in _compiler
return dialect.ddl_compiler(dialect, self, **kw)
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 319, in __init__
self.string = self.process(self.statement, **compile_kwargs)
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 350, in process
return obj._compiler_dispatch(self, **kwargs)
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/ext/compiler.py", line 436, in <lambda>
lambda *arg, **kw: existing(*arg, **kw),
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/ext/compiler.py", line 478, in __call__
return fn(element, compiler, **kw)
File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/ext/compiler.py", line 427, in _wrap_existing_dispatch
"compilation handler." % type(element)
sqlalchemy.exc.CompileError: <class 'alembic.ddl.base.ColumnComment'> construct has no default compilation handler.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
How to use alter_column in alembic? - Stack Overflow
To rename a column as of Alembic 0.9.5 I had to alter my migration to read as follows: op.alter_column('my_table', 'old_col_name', nullable=False, ...
Read more >Operation Reference — Alembic 1.9.0 documentation
Issue an “alter column” instruction using the current migration context. Generally, only that aspect of the column which is being changed, i.e. name,...
Read more >Database Migrations — barbican 2.0.1.dev9 documentation
Database migrations are managed using the Alembic library. ... Changing column attributes (types, names or widths) should be handled as follows:.
Read more >Python Friday #86: Database Migrations With Alembic and ...
Edit the alembic/env.py file ... folder = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) ... INFO [alembic.runtime.migration] ...
Read more >ALTER PRIMARY KEY | CockroachDB Docs
You cannot change the primary key of a table that is currently undergoing a primary key change, or any other schema change. ALTER...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Merged. Thanks for putting this together, @eeshugerman
I don’t know whether this is a problem at the SQLAlchemy level, Alembic level, or with this dialect.
Neither of the maintainers (me and @graingert) are active users of the project anymore, so we aren’t likely to be able to spend time investigating further. If you’re able to identify the problem, though, a PR would be welcome and I’ll try to prioritize reviewing and merging.