Setting up the database
- Create our models
- Create our database
First, go to the https://www.sqlite.org website.
open the download page https://www.sqlite.org/download.html.
After download set the path “sqlite” :- open system properties>environment variable >path>open new windows >edit>new(copy sqlite path )>ok.
open cmd administrator – give command sqlite3 (its show version sqlite)
SQLAlchemy is the Python SQL toolkit and Object Relational Mapper that gives application developers the full power sql.
pip install flask-sqlalchemy
Create database in our project-
open notes —app.py
Open your terminal
give command–python(open python terminal)
Command–from app import db
db.create_all()(this working means database create name â€œnoterâ€)
- When u creating a model for database table ,you will sometimes need to adjustments to the model,such as adding new row.
- Upon making these changes,you will need to migrate these changes in order to update the database table
- Pip install flask-migrate
Flask migrate command
- Set the Flask_APP environment variable> set FLASK_APP = “filename”
- Setup the migrations directory—flask db init
- Set up the migrations on file—- flask db
- migrate -m “some message”
- Update the database with the migration —-flask db upgrade
First create database-
Open terminal:– python shell
Command:->> from app import db
(your database created)
set FLASK_APP= “filename”
flask db init