A foreign key connects a row in one database table to a row in another by storing the related row’s ID. In Django, a ForeignKey model field creates that relationship column. section 4.7 section 4.7.2
Use the relationship shape to choose the database design:
- One-to-many: one venue can have multiple rooms, while each room belongs to one venue. section 4.7
- Many-to-many: use a separate relationship table containing foreign keys to both participating tables, rather than one ForeignKey column. section 4.7 section 4.7.2
- Django provides ForeignKey for one-way relationships and ManyToManyField for relationships that work in both directions. section 4.7 section 4.7.2
Rooms belonging to venues
Model a venue-to-room relationship with a ForeignKey on Room. The database stores the venue ID on each room row, allowing several rooms to reference one venue while keeping each room associated with a single venue. section 4.7
Figure 4.9 One-to-many vs. many-to-many relationships
Compare one-to-many foreign-key relationships with many-to-many relationships before choosing a Django model field. section 4.7

















