#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:
> - 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.
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.
{{{
# Removed some unrelated fields for clarity
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:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019b2602df5e-3c811e40-fcba-4609-b15a-737bfc5560ff-000000%40eu-central-1.amazonses.com.