Problem when using alembic with sqlalchemy_utils
In my sqlalchemy model, I am using choicetype sqlalchemy_utils:
id = db.Column(db.Integer, primary_key=True)
code = db.Column(db.Integer, nullable=True)
level = db.Column(mytypes.types.ChoiceType(LEVEL))
I did everything as described here http://alembic.readthedocs.org/en/latest/autogenerate.html#autogen-module-prefix . In my model, I imported the choicetype from my mytypes.types module:
from sqlalchemy_utils.types.choice import ChoiceType
added context to alembic / env.py
context.configure(
connection=connection,
target_metadata=target_metadata,
user_module_prefix="mytypes.types."
# ...
)
and in script.py.mako
import mytypes.types
... The problem is when I do a revision of my model I get something like this
from alembic import op
import sqlalchemy as sa
import mytypes.types
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('logging', sa.Column('level', mytypes.types.ChoiceType(length=255), nullable=True))
### end Alembic commands ###
Why didn't alembic pass the "LEVEL" argument to the choicetype and why did it pass length = 255 instead?
source to share
Alembic and SqlAlchemy-utils are not as friends as we expect. So import the models file into the alembic migration version file and change the update function accordingly.
How is it done here https://sqlalchemy-utils.readthedocs.io/en/latest/data_types.html#module-sqlalchemy_utils.types.choice
source to share