[Django] #25494: db_table option doesn't work in ManyToMany fields which using through option

10 views
Skip to first unread message

Django

unread,
Oct 3, 2015, 10:12:11 AM10/3/15
to django-...@googlegroups.com
#25494: db_table option doesn't work in ManyToMany fields which using through
option
----------------------------+--------------------------------
Reporter: mehranakk | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Keywords: db_table migration
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------
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

--
Ticket URL: <https://code.djangoproject.com/ticket/25494>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 3, 2015, 1:48:23 PM10/3/15
to django-...@googlegroups.com
#25494: db_table option doesn't work in ManyToMany fields which using through
option
------------------------------------+--------------------------------------
Reporter: mehranakk | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Normal | Resolution: needsinfo

Keywords: db_table migration | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------
Changes (by charettes):

* status: new => closed
* needs_better_patch: => 0
* resolution: => needsinfo
* needs_tests: => 0
* needs_docs: => 0


Comment:

Hi mehranakk,

I'm afraid I cannot reproduce the reported issue against the
`stable/1.8.x` and `master` branches using PostgreSQL with the provided
details.

Here's the two scenarios I've tried:

''In two steps''

1. Define the models with no explicit table name for the intermediary
model.
2. Create the initial migration via `makemigration`.
3. Alter the intermediary model definition to include an explicit table
name via the `db_table` option.
4. Create the second migration using `makemigration` and assert it
contains the appropriate `AlterModelTable` operation.
5. Run the migrations using `migrate` and assert the intermediary table
has the explicit table name as desired.

''In one step''

1. Define the models with an explicit table name for the intermediary
table via the `db_table` option.
2. Create the initial migration via `makemigration` and assert the
`CreateModel` operation has the correct `db_table` defined.
3. Run the migrations using `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.

--
Ticket URL: <https://code.djangoproject.com/ticket/25494#comment:1>

Reply all
Reply to author
Forward
0 new messages