Junior — Middle
How to perform database schema migration updates?
sobes.tech AI
Answer from AI
To update a database schema using migrations in Python, ORM tools like Django ORM or Alembic for SQLAlchemy are often used.
Example with Django:
- Make changes to models (models.py).
- Run the command to create migrations:
django-admin makemigrations
- Apply migrations to the database:
django-admin migrate
This will create or update tables, fields, and relationships in the database according to the model changes.
In Alembic (for SQLAlchemy), the process is similar: create migration scripts and apply them using the command alembic upgrade.
Thus, migrations allow managing database schema changes in a sequential and safe manner.