Setting up the database

  • Create our models
  • Create our database

SQLite:

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.

Test sqlite:

open cmd administrator – give command sqlite3 (its show version sqlite)

SQLAlchemy-

SQLAlchemy is the Python SQL toolkit and Object Relational Mapper that gives application developers the full power sql.

Command-

pip install flask-sqlalchemy

Create database in our project-
open notes —app.py

Program-

Open your terminal

give command–python(open python terminal)
Command–from app import db
db.create_all()(this working means database create name “noter”)

Flask migrate

  • 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-

class User(db.Model)-

Open terminal:– python shell

Command:->> from app import db
>> db.craete_all()

(your database created)

Migrates

command-
set FLASK_APP= “filename”

flask db init

Open chat