tortoise / aerich

A database migrations tool for TortoiseORM, ready to production.
https://github.com/tortoise/aerich
Apache License 2.0
823 stars 93 forks source link

Intermediate Table for ManyToManyRelation not being created #112

Open saintlyzero opened 3 years ago

saintlyzero commented 3 years ago
class Event(models.Model):
    id = fields.BigIntField(pk=True)
    name = fields.CharField(max_length=100)
    participants: fields.ManyToManyRelation["Team"] = fields.ManyToManyField(
        "models.Team", related_name="events", through="event_team"
    )

class Team(models.Model):
    id = fields.BigIntField(pk=True)
    name = fields.CharField(max_length=100)
    events: fields.ManyToManyRelation[Event]

I have these models Event and Team with a ManyToManyRelation specified via event_team.
When I run aerich migrate, schemas for the table event and team are generated, however, there's no schema being generated for event_team.

The only way I could autogenerate table event_team is by setting generate_schemas=True in register_tortoise()

Is there any other way I could get the schema of the intermediate table for ManyToManyRelation by aerich?

saintlyzero commented 3 years ago

@long2ice is this supported? or is it yet to be implemented?

long2ice commented 3 years ago

It should be supported yet, maybe bugs there.

saintlyzero commented 3 years ago

Okay, I'll check it out. Thanks :+1:

MaboUhha commented 3 years ago

Hello. In this case, the error is reproduced precisely with the migrate command, if you delete all migrations and run aerich init-db, intermediate table will be created

saintlyzero commented 3 years ago

@MaboUhha your suggestion might work, but I'll lose all of my existing migration files.

holma91 commented 1 year ago

it works if I delete all my migrations and do aerich init-db again, but this isn't really optimal