0Pricing
Flask Academy · Lesson

Define Relationships and Foreign Keys

Link models with one-to-many associations.

Rows That Belong Together

Real data connects: a user has many posts, an order has many items. A relationship links these rows in your models. 🔗

The Foreign Key

A foreign key is a column on the child that stores the parent's id. It is the actual link saved in the database.

user_id = db.Column(db.Integer, db.ForeignKey("user.id"))

All lessons in this course

  1. Fetch Rows with query and get
  2. Filter, Order, and Limit Results
  3. Define Relationships and Foreign Keys
  4. Joins and Lazy vs Eager Loading
← Back to Flask Academy