alembic: enum already exists
Describe the bug
Whenever I am adding Enum field in a new model it’s giving me this error “sqlalchemy.exc.ProgrammingError: (psycopg2.errors.DuplicateObject) type “tickettype” already exists” for resolving this I have to delete DB and create a new one.
Optional link from https://docs.sqlalchemy.org which documents the behavior that is expected
https://docs.sqlalchemy.org/en/14/errors.html#error-f405
SQLAlchemy Version in Use
1.4.46
DBAPI (i.e. the database driver)
2.9.5
Database Vendor and Major Version
2.9.5
Python Version
3.8
Operating system
Linux
To Reproduce
alembic revision --autogenerate -m "New Migration"
alemic upgrade head
Error
# Copy the complete stack trace and error message here, including SQL log output if applicable.
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.DuplicateObject) type “tickettype” already exists
[SQL: CREATE TYPE tickettype AS ENUM (‘PAID’, ‘FREE’, ‘GROUP’, ‘DONATION’, ‘REQUEST’, ‘GUESTLIST’)]
Additional context
No response
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 2
- Comments: 17 (7 by maintainers)
you are using the enum right here
that’s why it gets created. please see also https://github.com/sqlalchemy/alembic/issues/1347 if you want to use
create_typeand similar PG only optionsalembic doesnt generate migrations to add enums. The enum gets created only if you run CREATE TABLE via op.create_table(). I dont even see any code that would do this for add_column().
In the revision file that is generated by Alembic, where you have
upgrade()anddowngrade()defined. You write it insideupgrade().opshould be defined in the file already.