标签:_id mysql base pytho col mysq 操作 pre out
pip install flask_migrate
manager = Manager(app, db)
manager.add_command(‘db‘, MigrateCommand)
from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_script import Manager from flask_migrate import Migrate, MigrateCommand app = Flask(__name__) app.config[‘SQLALCHEMY_DATABASE_URI‘]=‘mysql://root:mysql@127.0.0.1:3306/flask_01‘ manager = Manager(app) db = SQLAlchemy(app) migrate = Migrate(app, db) # 使用migrate集成到script manager.add_command(‘db‘, MigrateCommand) class Book(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(20), nullable=True) hero_set = db.relationship(‘Hero‘, backref=‘book‘, lazy=‘dynamic‘) class Hero(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(20), nullable=True) book_id = db.Column(db.Integer, db.ForeignKey(‘book.id‘)) @app.route(‘/‘) def index(): return ‘index‘ if __name__ == ‘__main__‘: manager.run()
python 文件名 init
python 文件名 migrate
python 文件名 upgrade
标签:_id mysql base pytho col mysq 操作 pre out
原文地址:https://www.cnblogs.com/chao666/p/12424885.html