【发布时间】:2016-02-12 13:46:28
【问题描述】:
我正在尝试使此设置正常工作,数据库已正确创建,但尝试插入数据时出现以下错误:
在 sqlite 上:
sqlalchemy.exc.OperationalError
OperationalError: (sqlite3.OperationalError) no such column: Author [SQL: u'SELECT count(*) AS count_1 \nFROM (SELECT Author) AS anon_1']
在 postgres 上:
sqlalchemy.exc.ProgrammingError
ProgrammingError: (psycopg2.ProgrammingError) column "author" does not exist
LINE 2: FROM (SELECT Author) AS anon_1
^
[SQL: 'SELECT count(*) AS count_1 \nFROM (SELECT Author) AS anon_1']
编辑:也许这与它有关:我不明白为什么它说“anon_1”,因为我清楚地使用了凭据?
我已经检查了 postgres 和 sqlite 并且表格创建正确。这似乎是一个 ORM 配置错误,因为它似乎只发生在检查或创建条目时,欢迎提出任何建议!
class Author(CommonColumns):
__tablename__ = 'author'
author = Column(String(200))
author_url = Column(String(2000))
author_icon = Column(String(2000))
comment = Column(String(5000))
registerSchema('author')(Author)
SETTINGS = {
'SQLALCHEMY_TRACK_MODIFICATIONS': True,
'SQLALCHEMY_DATABASE_URI': 'sqlite:////tmp/test.db',
# 'SQLALCHEMY_DATABASE_URI': 'postgresql://xxx:xxx@localhost/test',
}
application = Flask(__name__)
# bind SQLAlchemy
db = application.data.driver
Base.metadata.bind = db.engine
db.Model = Base
db.create_all()
if __name__ == "__main__":
application.run(debug=True)
【问题讨论】:
标签: python postgresql flask sqlalchemy flask-sqlalchemy