Skip to content

When deleting a field with unqiue=True it will raise KeyError #364

@gck123

Description

@gck123

Describe the bug
When deleting a field with unqiue=True it will raise KeyError.

To Reproduce

version:
mysql8.0,tortoise-orm branch is develop(version 905daaa53928622b53454f65fd629690a7e5491f),aerich branch is dev(version 15d5612

Steps to Reproduction:

1.This is my model

class Tasks(Model):
    """任务表"""
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=100, unique=True, description="任务名称")
    status = fields.IntEnumField(enum_type=TaskStatus, description="任务状态")
    class Meta:
        table = "tb_tasks"

2.Init db

aerich init -t utils.config.TORTOISE_CONFIG
aerich init-db

3.Delete the name field of the model from step 2

class Tasks(Model):
    """任务表"""
    id = fields.IntField(pk=True)
    status = fields.IntEnumField(enum_type=TaskStatus, description="任务状态")
    class Meta:
        table = "tb_tasks"

4.Migrate and upgrade

aerich migrate
aerich upgrade

5.It will raise a exception
KeyError: 'name'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions