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

Migration with duplicate renaming of columns in some cases #380

Open
licongy opened this issue Dec 10, 2024 · 1 comment · May be fixed by #395
Open

Migration with duplicate renaming of columns in some cases #380

licongy opened this issue Dec 10, 2024 · 1 comment · May be fixed by #395
Labels
bug Something isn't working

Comments

@licongy
Copy link

licongy commented Dec 10, 2024

If there is ambiguity in the renaming of two columns in the model, the result will be that the migration engine will repeatedly try to do a renaming for each possibility.

for exapmle:

original:

class A(models.Model):
    is_active_node = fields.BooleanField(default=True)       
    is_active_default = fields.BooleanField(default=True)   

change to:

class A(models.Model):
    is_default_node = fields.BooleanField(default=True)   
    is_default = fields.BooleanField(default=True)             

The migrate will ask you with all the possible rename permutations, a total of 4 times. If you press enter all of them, then migrate will incorrectly generate all cases:

from tortoise import BaseDBAsyncClient

async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE "assistant_ais" RENAME COLUMN "is_active_node" TO "is_default_node";
        ALTER TABLE "assistant_ais" RENAME COLUMN "is_active_default" TO "is_default_node";
        ALTER TABLE "assistant_ais" RENAME COLUMN "is_active_node" TO "is_default";
        ALTER TABLE "assistant_ais" RENAME COLUMN "is_active_default" TO "is_default";"""

# and downgrade...

aerich version: 0.8.1 c2ebe9b

@waketzheng waketzheng added the bug Something isn't working label Dec 10, 2024
@waketzheng
Copy link
Contributor

Thanks for the report. This bug also exists on version v0.8.0, v0.7.2, v0.7.1, v0.6.3 -- tested with sqlite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants