0
0
Flaskframework~3 mins

Why Database migration in deployment in Flask? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if one small database change could break your whole live website?

The Scenario

Imagine you have a website with a database, and you want to add a new feature that needs extra columns or tables. You try to change the database by hand on the live server while the site is running.

The Problem

Manually changing the database is risky and slow. You might forget steps, cause errors, or break the site for users. It's hard to keep track of what changed and to fix problems quickly.

The Solution

Database migration tools automate these changes safely. They keep a history of changes, apply updates step-by-step, and let you update the database structure without downtime or mistakes.

Before vs After
Before
ALTER TABLE users ADD COLUMN age INT;
After
flask db migrate -m 'Add age column'
flask db upgrade
What It Enables

It lets developers update databases smoothly and confidently as the app grows and changes.

Real Life Example

A social media app adds a new feature to store user birthdays. Using migrations, the team updates the database without stopping the site or losing data.

Key Takeaways

Manual database changes are risky and error-prone.

Migrations automate and track database updates safely.

This keeps apps running smoothly during deployment.