先上代码#-*- coding: UTF-8 -*-from flask import Flaskfrom flask_script import Managerfrom flask_sqlalchemy import SQLAlchemyfrom sqlalchemy import Column,Integer,String,Sequence,Date,DateTimeapp = Flask(__name__)app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root@localhost:3306/py_demo'app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = Truedb = SQLAlchemy(app)manager = Manager(app)class User(db.model): __tablename__ = 'users' user_id = db.Column(db.Integer, primary_key = True) user_name = db.Column(db.String(80), unique = True) def __init__(self,user_name): self.user_name = user_name def __repr__(self): return '<User %r>' % self.user_nameif __name__ == '__main__': manager.run() 这代码,我从网上和书上多做了参考,在我的虚拟环境里写入 python tmp_sql.py shell会出现这个bug,明明照着书写的也有错,哈哈 也是醉了,然后把我db.model删除了吧能顺利进入但之后还是有bug.我就想,既然网上和书上都要求有个db.model。可是却有bug。求支教~~~
添加回答
举报
0/150
提交
取消