When running a migration on my Flask app's postgres database I get the following psycopg2 error on an Enum type:
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
INFO [alembic.runtime.migration] Running upgrade -> 8753d3c9dbd1, empty message
Traceback (most recent call last):
File "/home/jul/.miniconda3/envs/audiolabeling/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1182, in _execute_context
context)
File "/home/jul/.miniconda3/envs/audiolabeling/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 470, in do_execute
cursor.execute(statement, parameters)
psycopg2.ProgrammingError: type "feedbacktype" already exists
I tried to delete the alembic_version table and the migrations folder and rerun flask db init/migrate/upgrade, with no success.
I had to drop the database entirely to solve the issue.
Is there any way to not recreate types when they already exist ?
models.py
from audiolabeling import db
import enum
class FeedBackType(enum.Enum):
NONE = "none"
HIDDENIMAGE = "hiddenImage"
class Task(db.Model):
id = db.Column(db.Integer, primary_key=True)
feedback = db.Column(db.Enum(FeedBackType))
def __repr__(self):
return '<id {}>'.format(self.id)