[Django] #36802: ManyToManyField Table name changed (django 5.2 > django 6.0)

2 views
Skip to first unread message

Django

unread,
2:12 AM (12 hours ago) 2:12 AM
to django-...@googlegroups.com
#36802: ManyToManyField Table name changed (django 5.2 > django 6.0)
-------------------------------------+-------------------------------------
Reporter: ericmuijs | Type:
| Uncategorized
Status: new | Component: Database
| layer (models, ORM)
Version: 6.0 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Dear Django community.

Just upgraded to django 6. Most things seem to work fine. However, I get
an error when loading a fixture (during my tests) which has a many to many
relationship. The error is, table does not exists. The table does exists,
but somehow gets a different name in the (test database) compared to my
dev database. The difference in name is related to plural name vs normal
name.

Naming of the many to many table:
> Dev Database (tables created by django 5) :
base_vergunningproductgroep_producten (plural name of related model)
> Test database (tables created by django 6) :
base_vergunningproductgroep_product (just the name of the related

No code is changed, except for the upgrade to django 6.

{{{
class VergunningProductGroep(TenantModel):
vergunning = models.ForeignKey(Vergunning, on_delete=models.CASCADE,
related_name='vergunningproducten')
producten = models.ManyToManyField(Product,
related_name='vergunningproductgroepen')

class Product(TenantModel):
product_code = models.CharField(max_length=50)
omschrijving = models.CharField(max_length=50)
actief = models.BooleanField(default=True)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)

class Meta:
verbose_name = "product"
verbose_name_plural = "producten"
unique_together = ('tenant', 'product_code')
ordering = ['tenant','product_code']
indexes = [
models.Index(fields=['tenant', 'product_code'])
]
}}}

**Solution tried**
I tried to hardcode the db_table using:
{{{
class VergunningProductGroep(TenantModel):
vergunning = models.ForeignKey(Vergunning, on_delete=models.CASCADE,
related_name='vergunningproducten')
producten = models.ManyToManyField(Product,
related_name='vergunningproductgroepen',
db_table='vergunningproductgroep_producten')
}}}

But to no avail.


I already reported it [https://code.djangoproject.com/ticket/36800], but
based on my limited knowledge, it does seem unrelated to renaming? Sorry
if this tends to be a duplicate.
--
Ticket URL: <https://code.djangoproject.com/ticket/36802>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
2:13 AM (12 hours ago) 2:13 AM
to django-...@googlegroups.com
#36802: ManyToManyField Table name changed (django 5.2 > django 6.0)
-------------------------------------+-------------------------------------
Reporter: ericmuijs | Owner: (none)
Type: Uncategorized | Status: new
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by ericmuijs:

Old description:
New description:

Dear Django community.

Just upgraded to django 6. Most things seem to work fine. However, I get
an error when loading a fixture (during my tests) which has a many to many
relationship. The error is, table does not exists. The table does exists,
but somehow gets a different name in the (test database) compared to my
dev database. The difference in name is related to plural name vs normal
name.

Naming of the many to many table:
- Dev Database (tables created by django 5) :
base_vergunningproductgroep_producten (plural name of related model)
- Test database (tables created by django 6) :
base_vergunningproductgroep_product (just the name of the related

No code is changed, except for the upgrade to django 6.

{{{
class VergunningProductGroep(TenantModel):
vergunning = models.ForeignKey(Vergunning, on_delete=models.CASCADE,
related_name='vergunningproducten')
producten = models.ManyToManyField(Product,
related_name='vergunningproductgroepen')

class Product(TenantModel):
product_code = models.CharField(max_length=50)
omschrijving = models.CharField(max_length=50)

class Meta:
verbose_name = "product"
verbose_name_plural = "producten"
unique_together = ('tenant', 'product_code')
ordering = ['tenant','product_code']
indexes = [
models.Index(fields=['tenant', 'product_code'])
]
}}}

**Solution tried**
I tried to hardcode the db_table using:
{{{
class VergunningProductGroep(TenantModel):
vergunning = models.ForeignKey(Vergunning, on_delete=models.CASCADE,
related_name='vergunningproducten')
producten = models.ManyToManyField(Product,
related_name='vergunningproductgroepen',
db_table='vergunningproductgroep_producten')
}}}

But to no avail. db_table seems to be ignored completely.


I already reported it [https://code.djangoproject.com/ticket/36800], but
based on my limited knowledge, it does seem unrelated to renaming? Sorry
if this tends to be a duplicate.

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

Django

unread,
2:14 AM (12 hours ago) 2:14 AM
to django-...@googlegroups.com
#36802: ManyToManyField Table name changed (django 5.2 > django 6.0)
-------------------------------------+-------------------------------------
Reporter: ericmuijs | Owner: (none)
Type: Uncategorized | Status: new
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by ericmuijs:

Old description:

> Dear Django community.
>
> Just upgraded to django 6. Most things seem to work fine. However, I get
> an error when loading a fixture (during my tests) which has a many to
> many relationship. The error is, table does not exists. The table does
> exists, but somehow gets a different name in the (test database) compared
> to my dev database. The difference in name is related to plural name vs
> normal name.
>
> Naming of the many to many table:
# Removed some unrelated fields for clarity
Ticket URL: <https://code.djangoproject.com/ticket/36802#comment:2>

Django

unread,
2:17 AM (12 hours ago) 2:17 AM
to django-...@googlegroups.com
After running "makemigrations" I expect the issue to be resolved, but to
no avail. db_table seems to be ignored completely.

I already reported it [https://code.djangoproject.com/ticket/36800], but
based on my limited knowledge, it does seem unrelated to renaming? Sorry
if this tends to be a duplicate.

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36802#comment:3>

Django

unread,
2:17 AM (12 hours ago) 2:17 AM
to django-...@googlegroups.com
> After running "makemigrations" I expect the issue to be resolved, but to
> no avail. db_table seems to be ignored completely.
>
> I already reported it [https://code.djangoproject.com/ticket/36800], but
> based on my limited knowledge, it does seem unrelated to renaming? Sorry
> if this tends to be a duplicate.

New description:

Dear Django community.

Just upgraded to django 6. Most things seem to work fine. However, I get
an error when loading a fixture (during my tests) which has a many to many
relationship. The error is, table does not exists. The table does exists,
but somehow gets a different name in the (test database) compared to my
dev database. The difference in name is related to plural name vs normal
name.

Naming of the many to many table:
- Dev Database (tables created by django 5.2) :
Ticket URL: <https://code.djangoproject.com/ticket/36802#comment:4>

Django

unread,
2:43 AM (12 hours ago) 2:43 AM
to django-...@googlegroups.com
#36802: ManyToManyField Table name changed (django 5.2 > django 6.0)
-------------------------------------+-------------------------------------
Reporter: ericmuijs | Owner: (none)
Type: Uncategorized | Status: closed
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Clifford Gama):

* resolution: => duplicate
* status: new => closed

Comment:

Duplicate of #36800.
--
Ticket URL: <https://code.djangoproject.com/ticket/36802#comment:5>
Reply all
Reply to author
Forward
0 new messages