Steps to use:
1. Introduction of Flask-sqlalchemyfromimport= SQLAlchemy ()
2. Register flask-SQLAlchemy db.init_app (APP)
3. Import the tables in models fromimport *
4. Write class inherits Db. Model class Users (db. Model): __tablename__'users' = Column (Integer, primary _key=true)
5th step: Installing PIP3 install Flask-migrate
5.1 Import
Import Migrate, Migratecommand
Import Create_app, DB
5.2 Creating the Migrate sample
Migrate = Migrate (App, DB)
5.3 Create DB command
Manager.add_command (' db ', Migratecommand)
6th step
Execute command: initial: Python manage.py db init python manage.py db migrate #生成数据结构 python manage.py db upgrade
#在数据库中创建表信息
7th step:
When executing SQL later: mode one: = db.session.query (models. User.id,models. User.Name). All ()
db.session.remove () mode two: = models. Users.query.all ()
Python-flask-flask-sqlalchemy and Flask-migrate combined for data migration