2 ifwenvlook ifwenvlook 于 2016.03.24 20:32 提问

web开发时sqlalchemy报错

原本运行正常的web服务,在数据库模型中加了一行之后报错:
sqlalchemy.exc.OperationalError
sqlalchemy.exc.OperationalError: (OperationalError) no such column: comments.confirmed 'SELECT count(*) AS count_1 \nFROM (SELECT comments.id AS comments_id, comments.author_id AS comments_author_id, comments.post_id AS comments_post_id, comments.confirmed AS comments_confirmed \nFROM comments \nWHERE ? = comments.post_id) AS anon_1' (104,)

用的是python内置sqlite,代码如下:

class Comment(db.Model):
tablename = 'comments'
id = db.Column(db.Integer, primary_key=True)
body = db.Column(db.Text)
body_html = db.Column(db.Text)
timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
disabled = db.Column(db.Boolean)
author_id = db.Column(db.Integer, db.ForeignKey('users.id'))
post_id = db.Column(db.Integer, db.ForeignKey('posts.id'))
confirmed = db.Column(db.Boolean, default=False) ##就只是加了这一行,添加后也更新过数据库模型

shell中能查到这一列:

(venv) F:\flask\flask1>python manage.py db upgrade
INFO [alembic.migration] Context impl SQLiteImpl.
INFO [alembic.migration] Will assume non-transactional DDL.

(venv) F:\flask\flask1>python manage.py shell

~~Comment.confirmed

sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x000000000436BB70>

求帮忙,自学中……(:哭

3个回答

oyljerry
oyljerry   Ds   Rxr 2016.03.24 20:36

没有那一列,列名不正确。看配置好了没

ifwenvlook
ifwenvlook   2016.03.24 20:44

可是在shell中我能查到这一列……。这说明列是存在的吧

Comment.confirmed

ifwenvlook
ifwenvlook   2016.03.24 20:44

……为什么显示不出来

Comment.confirmed

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!