Technologies I am using:
- python 3.6
- postgres 10.4
- flask
- flask_migrate
- flask_sqlalchemy
So far I have relied on the autogenerated migration scripts that result from calling python app.py db migrate
. I then apply these migration scripts by calling python app.py db upgrade
. However my most recent change involves modifying an Enum that I have used to create a column. Here is a simplified example of my enum:
class EventType(Enum):
started = 1
completed = 2
aborted = 2
(Note the typo with the repeated value of 2.) Here is what I am attempting to change the Enum to:
class EventType(Enum):
started = 1
completed = 2
aborted = 3
failed = 4
My changes were to fix the typo and to add a new value to the enum.
Here is the (simplified) model that makes use of that enum:
class Event(db.Model):
id = db.Column(db.Integer, primary_key=True)
type = db.Column(db.Enum(EventType))
A call to python app.py db migrate
did not detect any changes and I have read in the documentation that alembic
(which is used under the hood in flask_migrate
) does not automatically detect enum changes. 1
This question from ~6 years ago seems to indicate there is a better way to handle this problem after Postgres 9.4
I am looking for the specific steps I need to take to either manually write my own migration script or to get flask_migrate
to detect this change and generate the script for me. Please let me know if I need to provide any more information to help with answering this question.