Database relationships in Django: Part 2

Today is all about Foreign Keys, which are the most common relational type that exists in an application. Often referred to as a One to Many relationship, where a single object can have many related items. Examples include a shopping cart having many items, a customer borrowing many books from a library or a user organising many events. In each case the following English statement is true:

"A Customer can borrow many books, but a book can only be borrowed by a single customer"

Again this simple sentence ought to convey the constraints on this relationship. This allows a single object to be referenced by multiple rows in another table with the reference being the primary key of the single object.

Tomorrow we will cover the final and most complex relation type Many to Many relationships