sqlalchemy / sqlalchemy/alembic

enum already exists

Open
#1,254 25 comments 13 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

autogenerate for enums awaiting info expected behavior postgresql
Dominant language
Python
Stars
4.4k
Forks
375
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the Alembic revision and upgrade commands, then inspect the generated migration and the PostgreSQL CREATE TYPE statement shown in the error. Compare the migration with the existing tickettype enum and determine what migration behavior should prevent the duplicate type error.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python, sqlalchemy
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.