from flask import Flask
from flask_sqlalchemy import SQLAlchemy
# from flask.ext.sqlalchemy import SQLAlchemy
#import config
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI']="mysql+pymysql://root:6187285@127.0.0.1:3306/db_deme2?charset=utf8"
db = SQLAlchemy(app)
class Article(db.Model):
__tablename__ = 'article'
id = db.Column(db.INTEGER, primary_key=True, autoincrement=True)
title = db.Column(db.String(100), nullable=False)
content = db.Column(db.text, nullable=False)
db.create_all()
@app.route('/')
def index():
return 'Hello, World!'
if __name__ == '__main__':
app.run(debug=True)
以下是报错信息:
AttributeError: 'function' object has no attribute '_set_parent_with_dispatch'Traceback (most recent call last):
File "E:/PycharmProjects/flaskLeaning/db_demo2.py", line 25, in
class Article(db.Model):
File "E:/PycharmProjects/flaskLeaning/db_demo2.py", line 29, in Article
content = db.Column(db.text, nullable=False)
File "D:\Program Files\Python36\lib\site-packages\sqlalchemy\sql\schema.py", line 1279, in __init__
self._init_items(*args)
File "D:\Program Files\Python36\lib\site-packages\sqlalchemy\sql\schema.py", line 90, in _init_items
item._set_parent_with_dispatch(self)
AttributeError: 'function' object has no attribute '_set_parent_with_dispatch'