image.png
from flask_sqlalchemy import SQLAlchemy WIN = sys.platform.startswith('win') if WIN: prefix = 'sqlite:///' else: prefix = 'sqlite:////' app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL', prefix os.path.join(app.root_path, 'data.db'))
是否追踪对象的修改
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
数据库模型: class Note(db.Model): id=db.Column(db.Interger,primary_key=True) body=db.Column(db.Text)
db类型: Integer String Text Date DateTime Interval Float Boolean PickleType LargeBinary
db类型参数: primary_key unique index :True nullable :是否为空 default
from app import db db.create_all()
重载DB输出
class Note(db.Model): def repr(self): return self.body