Opened 15 years ago
Last modified 9 years ago
#12810 closed
ManyToManyField.db_table — at Version 1
Reported by: | strelnikovdmitrij | Owned by: | nobody |
---|---|---|---|
Component: | Core (System checks) | Version: | dev |
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 |
Description (last modified by )
Originally from documentation.
ManyToManyField.db_table
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.
Reformatted, please use preview.