#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.

-- 
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/0107019b26007ff4-db1685cf-a2b2-4d20-bdcf-04aa1bce485e-000000%40eu-central-1.amazonses.com.

Reply via email to