SQLAlchemy with Flask

1 min


Basic knowledge of how SQLAlchemy works in Flask.

The system must have python:
– how to install python on Mac OS
– how to install python on Ubuntu

A virtual environment must also be created for the pip command to work. If it doesn’t exist yet:

We go inside the python virtual environment:

Let’s update pip:

pip install –upgrade pip

Installation:

pip install Flask-SQLAlchemy
pip install Flask-Migrate

Basic syntax in file __init__.py:

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate

def create_app():
app = Flask(__name__)

return app

app = create_app()
db = SQLAlchemy(app)
migrate = Migrate(app, db)


0 Comments

Leave a Reply