Skip to content

fix: m2m migrate raises TypeError #448

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

Merged
merged 3 commits into from
Apr 26, 2025

Conversation

waketzheng
Copy link
Contributor

Fixes #444

Currently, aerich does not handle changes of some attributions for m2m field migrating, such as null/unique/db_constraint.
This PR add a warning message for it.

For example::

  • old
from tortoise import Model, fields
class Group(Model):
    name = fields.CharField(max_length=30)

class User(Model):
    groups = fields.ManyToManyField('models.Group', unique=False)
  • new
from tortoise import Model, fields
class Group(Model):
    name = fields.CharField(max_length=30)

class User(Model):
    groups = fields.ManyToManyField('models.Group', unique=True)

Run aerich migrate will get this warning message:

Aerich does not handle 'unique' attribution for m2m field. You may need to change the constraints in db manually.

@waketzheng waketzheng merged commit a333605 into tortoise:dev Apr 26, 2025
15 checks passed
@waketzheng waketzheng deleted the fix-444-m2m-attr branch May 6, 2025 13:50
@waketzheng waketzheng mentioned this pull request May 12, 2025
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

Successfully merging this pull request may close these issues.

_handle_m2m_fields error on tortoise-orm 0.24.2
1 participant