Search⌘ K
AI Features

Getting Started with Models

Understand how to create database models in Flask using SQLAlchemy. This lesson guides you through defining a User model with attributes like email and password. Learn to set column data types and constraints, and how to create tables in the database. This foundation prepares you for managing data relationships in later lessons.

Introduction

You might recall that at the beginning of this course, we learned about three components of a web application:

  1. Views
  2. Templates
  3. Models

In previous lessons, we have covered two of these components (views and templates). In this lesson, we will figure out how to create models. Later in the course, we will also get to know how to manipulate these models.

Steps to create a User model in a database

Again, let’s get help from the example we have been using. We used a dictionary to store the user’s data.

users = {
    "archie.andrews@email.com": "football4life",
   
...