tortoise / aerich

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

`has_db_field` has no effect. #244

Closed tufbel closed 2 years ago

tufbel commented 2 years ago

I created a virtual field acronym and didn't want it to appear as a column in mysql :

class Company(models.Model):
    name = fields.CharField(max_length=32)
    acronym = fields.CharField(max_length=12,  has_db_field=False)

    class PydanticMeta(object):
        allow_cycles = True
        max_recursion = 1

    class Meta(object):
        table = f"{app_name}_company"

Use aerich after migration:

aerich migrate --name Company_acronym
-- upgrade --
ALTER TABLE `user_company` ADD `acronym` VARCHAR(12) NOT NULL;
-- downgrade --
ALTER TABLE `user_company` DROP COLUMN `acronym`;

The has db field=False I set does not work

long2ice commented 2 years ago

That's not the use case, has_db_field is used to custom field