aerich icon indicating copy to clipboard operation
aerich copied to clipboard

Problem mit default values from Enums

Open ninanomenon opened this issue 3 years ago • 2 comments

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';

ninanomenon avatar Jul 05 '22 08:07 ninanomenon

What's the version? Seems not problem for that since of https://github.com/tortoise/aerich/blob/dev/aerich/ddl/init.py#L75

long2ice avatar Jul 28 '22 07:07 long2ice

Sorry for the long reply time, I was on holiday. In the project I have here, I use version 0.6.3

ninanomenon avatar Aug 08 '22 10:08 ninanomenon