I am developing a flask microservice application. I get this issue when I use the command flask db migrate the database. I want to use OrderStatus class inside Enum function. I couldn't find the reason for this. Is the problem in my model or in my database configuration?
class OrderStatus(enum.Enum):
new = "NEW"
preparing = "PREPARING"
on_the_way = "ON THE WAY"
delivery = "DELIVERED"
cancel = "CANCEL"
class Order(db.Model):
""" Orders model for storing menu related data """
__tablename__ = 'order'
id = db.Column(db.Integer, primary_key=True)
order_id = db.Column(db.String(256),index=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), index=True)
menu_id = db.Column(db.Integer, db.ForeignKey('menu.id'), index=True)
restaurant_id = db.Column(db.Integer, db.ForeignKey('restaurant.id'), index=True)
status = db.Column(db.Enum(OrderStatus), default="New")
created_on = db.Column(db.DateTime, default=datetime.utcnow)```
This problem is on your migration.
Alembic revision --autogenerate create a wrong downgrate op, and don't drop the object enum on downgrate.
Create enum var outside of def upgrade
enum_type = sa.Enum("ONE", "TWO", "THREE", name="enum")
and update the column:
sa.Column("enum", enum_type, nullable=True)
On def downgrade add this line:
enum_type.drop(op.get_bind(), checkfirst=False)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With