this works fine for me:
def upgrade():
mytype = ENUM('a', 'b', 'c', create_type=False, name='myenum')
mytype.create(op.get_bind(), checkfirst=False)
op.create_table('t1',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('col1', mytype)
)
op.create_table('t2',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('col1', mytype)
)
output:
INFO [alembic.migration] Running upgrade None -> 47bed260c052, initial rev
INFO [sqlalchemy.engine.base.Engine]
SELECT EXISTS (
SELECT * FROM pg_catalog.pg_type t
WHERE t.typname = %(typname)s
AND pg_type_is_visible(t.oid)
)
INFO [sqlalchemy.engine.base.Engine] {'typname': u'myenum'}
INFO [sqlalchemy.engine.base.Engine] CREATE TYPE myenum AS ENUM ('a',
'b', 'c')
INFO [sqlalchemy.engine.base.Engine] {}
INFO [sqlalchemy.engine.base.Engine]
CREATE TABLE t1 (
id INTEGER NOT NULL,
col1 myenum
)
INFO [sqlalchemy.engine.base.Engine] {}
INFO [sqlalchemy.engine.base.Engine]
CREATE TABLE t2 (
id INTEGER NOT NULL,
col1 myenum
)
INFO [sqlalchemy.engine.base.Engine] {}
INFO [sqlalchemy.engine.base.Engine] INSERT INTO alembic_version
(version_num) VALUES ('47bed260c052')
INFO [sqlalchemy.engine.base.Engine] {}
INFO [sqlalchemy.engine.base.Engine] COMMIT
works with --sql too, output:
CREATE TYPE myenum AS ENUM ('a', 'b', 'c');
CREATE TABLE t1 (
id INTEGER NOT NULL,
col1 myenum
);
CREATE TABLE t2 (
id INTEGER NOT NULL,
col1 myenum
);
INSERT INTO alembic_version (version_num) VALUES ('47bed260c052');
COMMIT;
On 7/3/14, 3:23 PM, Anton wrote:
> Hey guys,
>
> I am facing the same issue, I am using PostgreSQL and want to use
> native ENUM type in two tables. For migration I am going to use alembic.
> Did you guys find out any was to do this?
>
> Thanks,
> Anton
>
> On Thursday, May 1, 2014 10:33:21 AM UTC-7, Michael Bayer wrote:
>
> OK. ENUM is something I’d have to dedicate several days of
> attention on :(
>
>
> On May 1, 2014, at 1:32 PM, Vlad Wing <[email protected]
> <javascript:>> wrote:
>
>> Yes, that's exactly what happend. I specified "create_type=False"
>> and it was ignored. Alembic tried to create the type anyway and,
>> of course, it failed.
>>
>> --
>> 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 [email protected] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/sqlalchemy
>> <http://groups.google.com/group/sqlalchemy>.
>> For more options, visit https://groups.google.com/d/optout
>> <https://groups.google.com/d/optout>.
>
> --
> 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 [email protected]
> <mailto:[email protected]>.
> To post to this group, send email to [email protected]
> <mailto:[email protected]>.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.