当我从msqlite切换到MariaDB时,我开始收到此错误。 ORM如何生成查询的语法似乎是问题,但我不知道如何解决它。更改paginate参数(例如“per_page”)仅会使参数显示为“-20,20”。
sqlalchemy.exc.ProgrammingError
ProgrammingError:(pymysql.err.ProgrammingError)(1064,u“你的SQL语法有错误;请查看与你的MariaDB服务器版本相对应的手册,以便在'-10,10'附近使用正确的语法第3行“)
[SQL:u'SELECT post.id AS post_id,post.title AS post_title,post.text AS post_text,post.publish_date AS post_publish_date,post.user_id AS post_user_id \ nFROM post ORDER BY post.publish_date DESC \ n LIMIT %(param_1)s,%(param_2)s'] [参数:{u'param_1': - 10,u'param_2':10}]
以下是查询帖子的行:
@blog_blueprint.route('/')
@blog_blueprint.route('/<int:page>')
@cache.cached(timeout=60)
def home(page=1):
posts = Post.query.order_by(Post.publish_date.desc()).paginate(page, 10)
recent, top_tags = sidebar_data()
return render_template(
'home.html',
posts=posts,
recent=recent,
top_tags=top_tags
)
第一个查询失败,第二个查询通过CLI工作:
MariaDB [flaskblog]> SELECT post.id AS post_id, post.title AS post_title,
post.text AS post_text, post.publish_date AS post_publish_date, post.user_id
AS post_user_id \n FROM post ORDER BY post.publish_date DESC LIMIT -10, 10;
MariaDB [flaskblog]> SELECT post.id AS post_id, post.title AS post_title,
post.text AS post_text, post.publish_date AS post_publish_date, post.user_id
AS post_user_id \n FROM post ORDER BY post.publish_date DESC LIMIT 0, 10;