File tree Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ from flask import Flask
2+ from flask_sqlalchemy import SQLAlchemy
3+ from flask_migrate import Migrate
4+ import config
5+
6+ app = Flask (__name__ )
7+ app .config .from_object (config .SQLiteConfig ) # Choose SQLiteConfig, MySQLConfig, or PostgreSQLConfig
8+
9+ db = SQLAlchemy (app )
10+ migrate = Migrate (app , db )
11+
12+ # Register models
13+ import models
14+
15+ # Route for testing
16+ @app .route ('/' )
17+ def index ():
18+ return "Flask-Migrate setup is working!"
19+
20+ if __name__ == '__main__' :
21+ app .run (debug = True )
Original file line number Diff line number Diff line change 1+ import os
2+
3+ class Config :
4+ SQLALCHEMY_TRACK_MODIFICATIONS = False
5+
6+ class SQLiteConfig (Config ):
7+ SQLALCHEMY_DATABASE_URI = 'sqlite:///site.db'
8+
9+ class MySQLConfig (Config ):
10+ SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://username:password@localhost/dbname'
11+
12+ class PostgreSQLConfig (Config ):
13+ SQLALCHEMY_DATABASE_URI = 'postgresql://username:password@localhost/dbname'
Original file line number Diff line number Diff line change 1+ from app import db
2+
3+ class User (db .Model ):
4+ id = db .Column (db .Integer , primary_key = True )
5+ username = db .Column (db .String (80 ), unique = True , nullable = False )
6+ email = db .Column (db .String (120 ), unique = True , nullable = False )
7+
8+ def __repr__ (self ):
9+ return f'<User { self .username } >'
Original file line number Diff line number Diff line change 1+ Flask == 2.3.2
2+ SQLAlchemy == 2.0.23
3+ Flask-Migrate == 4.0.4
4+ pymysql == 1.0.3 # For MySQL support
5+ psycopg2-binary == 2.9.7 # For PostgreSQL support
You can’t perform that action at this time.
0 commit comments