Introduction to Flask-SQLAlchemy
Lesson 1 of 2
  1. 1
    Web applications are often built around a lot of data that change frequently. The data is usually organized in entities related in some way. For example, entities such as users are related to produ…
  2. 2
    Flask-SQLAlchemy is an extension for Flask that supports the use of a Python SQL Toolkit called SQLAlchemy. To start creating a minimal application, in addition to importing Flask, we also need…
  3. 3
    The database object db created in our application contains all the functions and helpers from both SQLAlchemy and SQLAlchemy Object Relational Mapper (ORM). SQLAlchemy ORM associates user-defined …
  4. 4
    Adding another model or table schema to your application is simple. You only need to create another class that inherits from Model. The model you will create next, Reader, is simple and similar t…
  5. 5
    Often times in real-world applications we will have entities that are somehow related. Students take courses, customers buy products, and users comment on posts. In SQLAlchemy we can declare a *re…
  6. 6
    In the previous lesson, we began adding a one-to-many relationship to the Book and Reader models by using .relationship(). But that does not completely specify our one-to-many relationship. We addi…
  7. 7
    When you ran your application in the previous exercises you might have realized that there is no database file created in the application folder. The reason is simple: we need to explicitly initial…
  8. 8
    Now that we initialized our database schema, the next step is to start creating entries that will later populate the database. The beauty of SQLAlchemy Object Relational Mapper (ORM) is that our da…
  9. 9
    Creating objects for tables that have foreign keys is not much different from the usual creation of Python objects. Consider that we have the following objects already created: b1 = Book(id = 12…
  10. 10
    Congratulations on writing your first Flask app with database support! In this lesson, you have learned how to: * import Flask-SQLAlchemy and configure your app to support database connections. *…

What you'll create

Portfolio projects that showcase your new skills

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory