Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ehdgua01 opened this issue Oct 12, 2021 · 4 comments · Fixed by #428
Closed

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

ehdgua01 opened this issue Oct 12, 2021 · 4 comments · Fixed by #428
Labels
documentation Improvements or additions to documentation

Comments

@ehdgua01
Copy link
Contributor

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 ehdgua01 changed the title The type of the id field does not change. The type of the id field hasn't changed Oct 12, 2021
@PythonCoderAS
Copy link

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

@pydevup
Copy link

pydevup commented Jun 15, 2022

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

@kentaasvang
Copy link

kentaasvang commented Jan 4, 2024

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)

@waketzheng
Copy link
Contributor

Should show warning that pk field type migration does not support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants