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

The type of the id field hasn't changed #200

Open ehdgua01 opened 2 years ago

ehdgua01 commented 2 years ago

Hi,

The aerich automatically create id field as an IntField when I didn't define the id field. But I defined id as a BigIntField specifically but the aerich doesn't upgrade field to BigIntField if the field isn't ForeignKeyField

Before.

from tortoise import fields

class AbstractBaseModel(AbstractTimestampModel, AbstractActivatorModel):

    class Meta:
        abstract = True

class AuthServer(AbstractBaseModel):
    name = fields.CharField(max_length=64, unique=True)

    users: fields.ReverseRelation[User]

class User(orm.AbstractBaseModel):
    name = fields.CharField(max_length=10)
    identifier = fields.CharField(max_length=100)
    auth_server = fields.ForeignKeyField(
        model_name="models.AuthServer",
        related_name="users",
        on_delete=fields.RESTRICT,
    )

After.

from tortoise import fields

class AbstractBaseModel(AbstractTimestampModel, AbstractActivatorModel):
    id = fields.BigIntField(pk=True)

    class Meta:
        abstract = True

class AuthServer(AbstractBaseModel):
    name = fields.CharField(max_length=64, unique=True)

    users: fields.ReverseRelation[User]

class User(AbstractBaseModel):
    name = fields.CharField(max_length=10)
    identifier = fields.CharField(max_length=100)
    auth_server = fields.ForeignKeyField(
        model_name="models.AuthServer",
        related_name="users",
        on_delete=fields.RESTRICT,
    )

But the aerich create DDL only for the auth_server_id column

-- upgrade --
ALTER TABLE `user` MODIFY COLUMN `auth_server_id` BIGINT NOT NULL;
-- downgrade --
ALTER TABLE `user` MODIFY COLUMN `auth_server_id` INT NOT NULL;
PythonCoderAS commented 2 years ago

I also have this problem, but I'm going from a bigint to a normal int.

pydevup commented 2 years ago

I also have this problem, change IntField to BigIntField has no effect. aerich says 'No changes detected'.

kentaasvang commented 7 months ago

Also get "No changes detected" when trying to change id field type from IntField to UUIDField

Before:

class User(models.Model):
    """
    The User model
    """
    id = fields.IntField(pk=True)

After:

class User(models.Model):
    """
    The User model
    """
    id = fields.UUIDField(pk=True)