tortoise / aerich

A database migrations tool for TortoiseORM, ready to production.
https://github.com/tortoise/aerich
Apache License 2.0
820 stars 94 forks source link

aerich 表的 content 字段内容会变的一致 #178

Closed panla closed 3 years ago

panla commented 3 years ago

question

表现: 不同迁移的 content 字段内容会一致

version

config.py

TORTOISE_ORM = {
    'connections': {
        'default': {
            'engine': 'tortoise.backends.mysql',
            'credentials': {
                'database': 'demo',
                'host': '172.20.0.2',
                'password': '12345678',
                'port': 3306,
                'user': 'root',
                'minsize': 1,
                'maxsize': 5,
                'charset': 'utf8mb4'
            }
        }
    },
    'apps': {
        'models': {
            'models': [
                'aerich.models',
                'apps.models.__init__'
            ],
            'default_connection': 'default',
        },
    },
    'use_tz': False,
    'timezone': 'Asia/Shanghai'
}

model

from enum import Enum

from tortoise import Model, fields

from tortoise.fields import BigIntField, IntField, CharEnumField

class ColorEnum(str, Enum):
    RED = '1'
    GREEN = '2'
    BLUE = '3'
    YELLOW = '4'
    GRAY = '5'

class Cup(Model):
    id = BigIntField(pk=True)
    price = IntField()
    sell_num = IntField()
    color = CharEnumField(ColorEnum, default=ColorEnum.RED)

    class Meta:
        table = 'cups'

init

from tortoise.contrib.fastapi import register_tortoise

register_tortoise(
        app,
        config=config.TORTOISE_ORM
    )

过程

在数据库 A 先后进行了迁移一,迁移二,迁移三,此时,aerich 表的 content 字段内容不同

然后,更换到数据库 B 执行 aerich upgrade 此时 aerich 表的 content 字段内容全部相同

最后

这个算正常还是不正常?

long2ice commented 3 years ago

正常