With our database models created and ready for use, the next thing is to migrate these database models to the database server that we are using to run the application. The process to do this is quite straightforward.
To migrate the models to the database server, we first expose them into the application root. For example, to migrate the database models related to the users and products, all we need to do is to add the following line to the bugzot/__init__.py file:
from bugzot.models import ActivationKey, Category, Component, Product, Role, User, Version
Once this is done, all we need to do is to call the create_all() method of the SQLAlchemy database object we created. This can be done by adding the following line to the end of the bugzot/__init__.py file:
db.create_all()
Once this is done, our bugzot/__init__.py it looks something like the following:
'''
File: __init__.py
Description: Bugzot application entrypoint file.
'''
from .application import app, bcrypt, db
from bugzot.models import ActivationKey, Category, Component, Product, Role, User, Version
db.create_all()
With this done, the next time we start our application, the database models will be migrated to the database and be made available for use.