aerich icon indicating copy to clipboard operation
aerich copied to clipboard

Intermediate Table for ManyToManyRelation not being created

Open saintlyzero opened this issue 5 years ago • 6 comments

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 avatar Dec 26 '20 07:12 saintlyzero

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

saintlyzero avatar Jan 05 '21 06:01 saintlyzero

It should be supported yet, maybe bugs there.

long2ice avatar Jan 05 '21 06:01 long2ice

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

saintlyzero avatar Jan 05 '21 10:01 saintlyzero

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

MaboUhha avatar Jan 22 '21 13:01 MaboUhha

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

saintlyzero avatar Jan 22 '21 16:01 saintlyzero

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

holma91 avatar Jun 21 '23 07:06 holma91