Skip to content
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

No migration occurs as expected when adding unique=True to field #404

Open
licongy opened this issue Jan 11, 2025 · 0 comments
Open

No migration occurs as expected when adding unique=True to field #404

licongy opened this issue Jan 11, 2025 · 0 comments

Comments

@licongy
Copy link

licongy commented Jan 11, 2025

No migration occurs as expected when adding unique=True to field.

For example, if you originally had a model:

class Example(models.Model):
    id = SnowflakeIDField()
    name = fields.CharField(max_length=64, null=False, db_index=True)

then you add a constraint to the name field:

class Example(models.Model):
    id = SnowflakeIDField()
    name = fields.CharField(max_length=64, null=False, db_index=True, unique=True)

the migration you expect to get should be:

async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        DROP INDEX IF EXISTS "idx_example_name_a7b9a6";
        CREATE UNIQUE INDEX "idx_example_name_a7b9a6" ON "example" ("name");
        """

or at least:

async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE "example"
        ADD CONSTRAINT "example_name_a7b9a6" UNIQUE ("name");
        """

However, the practical result is that no migration files are produced.


Version:
aerich : 0.8.1 ac847ba
tortoise-orm : 0.23.0
asyncpg : 0.30.0
postgresql : 17.2
python : 3.12

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

No branches or pull requests

1 participant