SQLite, SQLAlchemy & Alembic: Database Setup for Python

Day 3: SQLite, SQLAlchemy & Alembic CRUD needs some memory, and that's what day 3 is about. We swap out the in-memory Python list for a real SQLite database — adding SQLAlchemy as the ORM and Alembic to manage schema changes over time. If you've used Eloquent + Laravel migrations, the mental model is nearly identical. Here's what we cover: → Setting up SQLAlchemy's three core pieces: engine, session factory, and declarative base → Defining ORM models with a one-to-many relationship (tasks → notes) and cascade deletes → Wiring Alembic so autogenerate actually works (the __init__.py trick that trips everyone up) → The session lifecycle: why db.commit() is the single most common mistake → Running a real schema migration — adding a column to a live database without touching the file directly The part worth highlighting: the service/route separation from Day 2 paid off immediately. The routes layer barely changed. The database swap was almost entirely contained to the service layer. That's the point of keeping them separate. By the end, you stop the server, restart it, and your data is still there. 👉🏼 Read the full article - link is in the comments. #Python #Starlette #SQLAlchemy #WebDevelopment #BackendDevelopment

To view or add a comment, sign in

Explore content categories