Creating Tables with Flask and SQLAlchemy
📖 Scenario: You are building a simple web app to store information about books in a library. You want to create a database table to hold the book details.
🎯 Goal: Create a Flask app with SQLAlchemy that defines a Book model and creates the corresponding table in the database using db.create_all().
📋 What You'll Learn
Create a Flask app instance named
appCreate a SQLAlchemy database instance named
db linked to appDefine a
Book model with columns id (integer primary key), title (string), and author (string)Use
db.create_all() to create the tables in the database💡 Why This Matters
🌍 Real World
Creating tables is the first step in building web apps that store data persistently, like user info, products, or posts.
💼 Career
Understanding how to define models and create tables is essential for backend web development roles using Flask and SQLAlchemy.
Progress0 / 4 steps