Opened 9 years ago
Closed 9 years ago
#25494 closed Bug (needsinfo)
db_table option doesn't work in ManyToMany fields which using through option
Reported by: | Mehran Akhavan | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.8 |
Severity: | Normal | Keywords: | db_table migration |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have a model which contains a ManyToMany field using the through option. I wanted to change the name of the many to many table, so I added db_table in Meta class of through model. After running makemigrations and migrate commands, I have a tables with default names.
class MyModel(models.Model): my_field = models.ManyToManyField(AnotherModel, through='IntermediateModel') class IntermediateModel(models.Model): class Meta: db_table = 'my_intermediate_name' my_model = models.ForeignKey(MyModel) another_model = models.ForeignKey(AnotherModel)
I run these commands:
python manage.py makemigrations python manage.py migrate
I'm using postgresql 9.4.4
Note:
See TracTickets
for help on using tickets.
Hi mehranakk,
I'm afraid I cannot reproduce the reported issue against the
stable/1.8.x
andmaster
branches using PostgreSQL with the provided details.Here's the two scenarios I've tried:
In two steps
makemigration
.db_table
option.makemigration
and assert it contains the appropriateAlterModelTable
operation.migrate
and assert the intermediary table has the explicit table name as desired.In one step
db_table
option.makemigration
and assert theCreateModel
operation has the correctdb_table
defined.migrate
and assert the intermediary table has the explicit table name as desired.Please re-open this ticket if you can provide more info. A detailed step by step description of the actions performed would help.