计算机/cs操作记录
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import pymysql
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:root@localhost/apple'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True # 每次请求结束
db = SQLAlchemy(app) # db 对象是 SQLAlchemy 类的实例,表示程序使用的数
class User(db.Model):
__tablename__ = 'user' # 该模型对应的表名
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(20), unique=True, index=True) # 定 义姓名字段
birthday = db.Column(db.Date, nullable=False) # 定 义生日字段
money = db.Column(db.Float, default=0.0)
if __name__ == '__main__':
db.create_all()