Flask[Part 2]: Setting up Database

Introduction

This article is a continuation of our Previous Post where we tackled setting up working directory, working environment , installing flask and run a flask app.
In this article we will focus on creating models , migrations and te…


This content originally appeared on DEV Community and was authored by Tito

Introduction

This article is a continuation of our Previous Post where we tackled setting up working directory, working environment , installing flask and run a flask app.
In this article we will focus on creating models , migrations and testing database

Prerequisite

  • python 3+ installed
  • Flask Installed; A working flask app
  • PostgreSQL optional; work with DBMS of your choice

Before you start, create a model.py file in project folder and install ,import the following packages:

  • flask-login
  • flask-sqlalchemy
  • flask-migrate
  • itsdangerous Alt Text On the database configuration, it is advisable to hide the db details using environment variables.

Now Go ahead the model
Alt Text

After creating our model and ensuring that the DBMS of your choice is working, carry out a migration:

(env) tito@tito-HP-2000-Notebook-PC:~/Desktop/Milestone/Mile_Proj$ flask db init
(env) tito@tito-HP-2000-Notebook-PC:~/Desktop/Milestone/Mile_Proj$ flask db migrate

The migrations will automatically create tables in your Database.
Thank you for following .
The next article , I will handle forms for collecting data.
------------------------------------ NEXT ARTICLE------------------------------------


This content originally appeared on DEV Community and was authored by Tito


Print Share Comment Cite Upload Translate Updates
APA

Tito | Sciencx (2021-08-26T14:35:29+00:00) Flask[Part 2]: Setting up Database. Retrieved from https://www.scien.cx/2021/08/26/flaskpart-2-setting-up-database/

MLA
" » Flask[Part 2]: Setting up Database." Tito | Sciencx - Thursday August 26, 2021, https://www.scien.cx/2021/08/26/flaskpart-2-setting-up-database/
HARVARD
Tito | Sciencx Thursday August 26, 2021 » Flask[Part 2]: Setting up Database., viewed ,<https://www.scien.cx/2021/08/26/flaskpart-2-setting-up-database/>
VANCOUVER
Tito | Sciencx - » Flask[Part 2]: Setting up Database. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/26/flaskpart-2-setting-up-database/
CHICAGO
" » Flask[Part 2]: Setting up Database." Tito | Sciencx - Accessed . https://www.scien.cx/2021/08/26/flaskpart-2-setting-up-database/
IEEE
" » Flask[Part 2]: Setting up Database." Tito | Sciencx [Online]. Available: https://www.scien.cx/2021/08/26/flaskpart-2-setting-up-database/. [Accessed: ]
rf:citation
» Flask[Part 2]: Setting up Database | Tito | Sciencx | https://www.scien.cx/2021/08/26/flaskpart-2-setting-up-database/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.