aerich icon indicating copy to clipboard operation
aerich copied to clipboard

The type of the id field hasn't changed

Open ehdgua01 opened this issue 4 years ago • 3 comments

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;

ehdgua01 avatar Oct 12 '21 03:10 ehdgua01

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

PythonCoderAS avatar Apr 10 '22 22:04 PythonCoderAS

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

pydevup avatar Jun 15 '22 13:06 pydevup

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)

kentaasvang avatar Jan 04 '24 20:01 kentaasvang