As applications evolve, their data models also evolve. Developers may need to add new fields, change existing ones, or introduce completely new tables to support new features. In SQL-based systems, these changes must also be reflected in the database schema. If the code changes but the database does not, the application will break or behave incorrectly.
Alembic is a tool used together with SQLAlchemy to manage these database schema changes in a controlled and safe way. Instead of manually writing SQL scripts every time a change happens, Alembic helps developers track, generate, and apply these changes step by step.
The process starts when the developer updates the SQLAlchemy model. For example, a Movie table might originally have only id and title, and later the developer adds a new field such as rating. At this point, only the Python model has changed, not the database itself.
To detect and prepare this change for the database, the developer runs:
alembic revision --autogenerate -m "add rating column"






