# -*- coding:utf-8 -*-
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:123456@localhost:3306/flask_sql'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
#数据库模型
class Role(db.Model):
__tablename__ = 'roles'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(16), unique = True)
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(16), unique=True)
role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
db.create_all()
app.run(debug = True)pymysql和sqlAlchemy驱动都装上了,驱动也都也导入了项目里,可是运行后数据库里的flask_sql没有任何新数据显示,不知道怎么回事,运行后也没有报错。
添加回答
举报
0/150
提交
取消