Flask Creating SQLite3 Table and Database

Every table in the database must be created. This is done before the Flask server is started otherwise it causes errors.

I’ll be using the F5 Info page.

Creating the Table Models.py

The models.py file is what contains all the Python classes for the database tables.

Setting up the Database

This must be run before the Flask application will work correctly. I’m sure there will be a way to create the database tables automatically, but for now I am using this method as you only have to do it when adding new tables.

Drawbacks

As I said this must be ran when you add a new table. This also goes fore adding new fields to an existing table.
The database must be deleted and then recreated. So all the data is lost in all tables. This hasn’t been an issue for me in this project.

Files to delete;

  • data.sqlite (this may be named differently, it should be under__init__.py
  • migrations directory

Leave a Comment

Your email address will not be published. Required fields are marked *