aerich
aerich copied to clipboard
Problem mit default values from Enums
The mysql migration that aerich generates for enums has a problem with defaults
This state here causes an error:
ALTER TABLE `station` ALTER COLUMN `connection` SET DEFAULT 'Connection.OFFLINE'
pymysql.err.OperationalError: (1067, "Invalid default value for 'connection'")
The model on which this is based on:
class Connection(Enum):
ONLINE = "online"
OFFLINE = "offline"
class Station(Base):
...
connection: Connection = fields.CharEnumField(enum_type=Connection, default=Connection.OFFLINE)
...
After adjusting the alter table statement, upgrading the database to the latest migration works.
ALTER TABLE 'station' ALTER COLUMN 'connection' SET DEFAULT 'OFFLINE';
What's the version? Seems not problem for that since of https://github.com/tortoise/aerich/blob/dev/aerich/ddl/init.py#L75
Sorry for the long reply time, I was on holiday. In the project I have here, I use version 0.6.3