definition: The Ask extension encapsulates the SQLAlchemy framework. In Flask-sqlalchemy, the database is specified using a URL, and the following table lists the common database engines and the corresponding URLs.
Installation: Pip Install Flask-sqlalchemy
Pip Install Flask-migrate
# Boot file
fromFlask_scriptImportManager,server fromFlask_migrateImportmigratecommand,migrate fromRbacImportCreate_app,dbapp=Create_app () Manager=Manager (APP) Migrate=Migrate (app,db) Manager.add_command ("Runserver", Server ()) Manager.add_command ("DB", Migratecommand)if __name__=='__main__': Manager.run ()
# Startup file Startup Auto Trigger
fromFlaskImportFlask fromConfig.settingImportBaseconfig#Import Flask-sqlalchemy fromFlask_sqlalchemyImportSqlalchemydb=SQLAlchemy () from. views.userImportUser#Import a table in models from. model.modelsImport*defCreate_app (): App= Flask (__name__) app.register_blueprint (user) Db.init_app (APP)returnApp
Execute command:
First:
Python manage.py DB init
Python manage.py db Migrate
Python manage.py DB Upgrade
II: (view) generate all plugins for the current environment
Generate all dependencies for the current environment: Requirements.txt
PIP3 Freeze > Requirements.txt
Generate all dependencies for the current program: Requirements.txt
PIP3 Install Pipreqs
Pipreqs./
Flask ORM Framework----------Flask-sqlalchemy Application