Opened 11 years ago

Last modified 4 years ago

#12810 closed

ManyToManyField.db_table — at Initial Version

Reported by: strelnikovdmitrij Owned by: nobody
Component: Core (System checks) Version: master
Severity: Normal Keywords: ManyToManyField
Cc: berker.peksag@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Originally from documentation.
The name of the table to create for storing the many-to-many data. If this is not provided, Django will assume a default name based upon the names of the two tables being joined.

It is a little bit unclear, cause if db_table is not provided, Django will create table with name based on the name of the model (table that has the ManyToManyField), and field name that contain this ManyToManyField.

class Product(models.Model):

color = models.ManyToManyField('ProductColor', null=True, blank=True)
class Meta:

db_table = 'eshop_product'

class ProductColor(models.Model):

name = ...
class Meta:

db_table = 'eshop_product_color'

running syncdb
after the creation of 'eshop_product' table Django will create 'eshop_product_color' table that holds relation between Product and ProductColor. The table for ProductColor will never create.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top