-
Notifications
You must be signed in to change notification settings - Fork 3
Database Migration
The migration of changes to the database is accomplished using the Flask-Migrate extension. An easy example of setting up the migration can be found in the following tutorial Flask Database Migration. The tutorial uses PostgreSQL but the procedure is the same for SQLite3. The manage file is already contained in the repository with the name db_manage.py.
To properly do migrations follow the following steps:
- Initialise the migration by running the following command in the root directory of the app.
$ python db_manage.py db init - Create a migration:
$ python db_manage.py db migrate - Update the database with the migration:
$ python db_manage.py db upgrade
After these commands are executed all the changes will be applied to the database and it should be ready for use.
Migrations are necessary when changes are made to the database schema in the code. This will ensure that the database based on the old code will still work with the new schema. As mentioned the setup file to handle the migrations is already setup and therefore no changes need to be made to this file.