Flask-migrate is an extension module of flask, which mainly extends the structure of database tables.
Official Document: http://flask-migrate.readthedocs.io/en/latest/
Use flask-migrate need to rely on flask-script components, see my other blog--Flask-script detailed
Installation
Pip Install Flask-migrate
Creating commands with examples
From flask import flaskfrom flask_sqlalchemy import sqlalchemyfrom flask_script import managerfrom flask_migrate import Mi Grate, Migratecommandapp = Flask (__name__) app.config[' sqlalchemy_database_uri '] = ' sqlite:///app.db ' db = SQLALCHEMY ( APP) Migrate = Migrate (app, db) Manager = Manager (APP) Manager.add_command (' db ', Migratecommand) class User (db). Model): ID = db. Column (db. Integer, primary_key=true) name = db. Column (db. String (*)) if __name__ = = ' __main__ ': manager.run ()
Execute command
$ python manage.py db init initializes the database, creates a Migations folder, and generates a Alembic_version table in the database $ Python manage.py db migrate Create migration History $ python manage.py db upgrade update database
Pit 1. Default values for fields when designing tables
operator = db. Column (db. String (nullable=true), server_default= "Init_data")
Here is the parameter Server_default instead of the default
2. If you report this error
Heroku Postgres, db migrate Fail:alembic.util.exc.CommandError:Can ' t locate revision identified by
Delete the data from the Alembic_version table
Flask's Flask-migrate Database migration