alembic problem autogenerating migration scripts with sqlalchemy-utils column types

724 views
Skip to first unread message

Ons

unread,
Jan 5, 2015, 12:06:05 PM1/5/15
to sqlal...@googlegroups.com
Hello,

I have a sqlalchemy model to which i want to add a column using alembic :

from sqlalchemy_utils import UUIDType
new_column = Column(UUIDType, primary_key=True)

When i run alembic revision --autogenerate, it generates a migration script but when i run alembic upgrade head it throws the error below:

    op.add_column('my_model', sa.Column('my_model_uuid', sa.UUIDType(length=16), nullable=False))
AttributeError: 'module' object has no attribute 'UUIDType'

How can i configure alembic to generate migration scripts using data types from sqlalchemy_utils ?

Michael Bayer

unread,
Jan 5, 2015, 12:11:35 PM1/5/15
to sqlal...@googlegroups.com
First off, update to the latest alembic - your custom type will no longer output as part of “sa.” - it will use __module__ instead.

Secondly, you can configure this fully. See http://alembic.readthedocs.org/en/latest/autogenerate.html#autogen-module-prefix for a full documentation section on just this issue.


Ons

unread,
Jan 6, 2015, 4:39:35 AM1/6/15
to sqlal...@googlegroups.com
i am using the latest version (alembic 0.7.3). I still have the same error even after adding the user_module_prefix configuration. it still uses sa. as a prefix for types from sqlalchemy_utils.

Michael Bayer

unread,
Jan 6, 2015, 9:48:46 AM1/6/15
to sqlal...@googlegroups.com
Well, the logic currently does this to determine if the type is a SQLAlchemy type:

elif mod.startswith("sqlalchemy"):
prefix = _sqlalchemy_autogenerate_prefix(autogen_context)
return "%s%r" % (prefix, type_)
else:
prefix = _user_autogenerate_prefix(autogen_context, type_)
return "%s%r" % (prefix, type_)

so for the moment you’ll need to implement the “render_item” function as documented in http://alembic.readthedocs.org/en/latest/autogenerate.html#affecting-the-rendering-of-types-themselves.

https://bitbucket.org/zzzeek/alembic/issue/261/for-type-namespace-startswith-sqlalchemy is added.
> --
> You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.
> To post to this group, send email to sqlal...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages