add "create_type" to sqltypes.Enum ?
this type has a "name" argument that only applies to PostgreSQL. So the type already has "backend specific" arguments, and it having a name implies directly that there's a separate CREATE statement. so we should have create_type directly present. See https://github.com/sqlalchemy/alembic/issues/1347
it probably makes sense. don't we support actual enum also in another db? Mariadb/Mysql supports them https://mariadb.com/kb/en/enum/ too, but I'm not sure if they need to be created or not
Hello all,
I would like to take this issue.
I can investigate this and try to solve.
Feel free to ask question here or on gitter. Emulated types like enum are not the easiest to work with, but this issue may be easy enough!
This will be quite helpful!
Mike Bayer has proposed a fix for this issue in the main branch:
add create_type to Enum https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6162
Sorry to revive this, but I guess I'm missing something. Is that proposed fix is already up?
When I try to use sqlalchemy.Enum("OK", "NICE", name="my_enum", create_type=False) I still get the same error mentioned in https://github.com/sqlalchemy/alembic/issues/1347 if my enum is already created.
Using postgresql.ENUM works fine...
are you using the latest 2.1 branch from main? that's where this is
AH! Ok that makes sense, thanks 💪🏻
Hey, I am using the main branch and it seems to be handling ENUMs correctly with create_type = False. The problem is that it adds metadata=MetaData() to the migration file but it does not auto import from sqlalchemy import MetaData.
~~if you are indicating metadata=MetaData() in your Enum (which is unnecessary?) add that import to your alembic template.~~
~~but....there shouldn't be any need to set an empty MetaData on your Enum~~ this happens due to the Table
>>> from sqlalchemy import Enum, MetaData
>>> repr(Enum("x", "y", "z", create_type=False))
"Enum('x', 'y', 'z', create_type=False)"
>>> repr(Enum("x", "y", "z", create_type=False, metadata=MetaData()))
"Enum('x', 'y', 'z', metadata=MetaData(), create_type=False)"
Hey, I am using the main branch and it seems to be handling ENUMs correctly with create_type = False. The problem is that it adds metadata=MetaData() to the migration file but it does not auto import from sqlalchemy import MetaData.
@CaselIT I think this is a 2.1 regression ^^^^
>>> from sqlalchemy import Table, Column, Enum, MetaData
>>> e1 = Enum("x", "y", "z", create_type=False)
>>> t = Table("t", MetaData(), Column("q", e1))
>>> repr(e1)
"Enum('x', 'y', 'z', metadata=MetaData(), create_type=False)"
it doesnt make sense for it to repr() like that (for one, it's wrong, that's not a blank MetaData, it's the one that's on the Table)
I agree, we can likely remove metadata from the repr
Federico Caselli referenced this issue:
Omit metadata kw from Enum repr https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6568
note that alembic PR https://github.com/sqlalchemy/alembic/pull/1795 for alembic issue https://github.com/sqlalchemy/sqlalchemy/issues/13140 likely fixes this