简体   繁体   English

Heroku Postgresql运算符不存在

[英]Heroku postgresql operator does not exist

I deployed my site to Heroku running postgresql. 我将我的网站部署到运行Postgresql的Heroku。 Before, I had it on the flask development environment running sqlite. 以前,我在运行sqlite的flask开发环境中使用过它。 The app ran fine when using the schedule view, but when I access the schedule view from Heroku, I get an error. 使用计划视图时,该应用程序运行良好,但是当我从Heroku访问计划视图时,出现错误。

CLASS

class Task(db.Model):

id = db.Column(db.Integer, primary_key=True)

name = db.Column(db.String(80), index=True)

description = db.Column(db.String(200), index=True)

priority = db.Column(db.Integer)

is_complete = db.Column(db.Boolean)  ####might be trouble

url = db.Column(db.String(200), index=True)

est_dur = db.Column(db.Integer)
time_quad = db.Column(db.Integer)

timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)

user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

ROUTE 路线

@bp.route('/schedule')
#@login_required
def schedule():


currentUser = current_user.id

q1 = Task.query.filter_by(time_quad=1).filter_by(user_id=currentUser).filter_by(is_complete=0).all()

q2 = Task.query.filter_by(time_quad=2).filter_by(user_id=currentUser).filter_by(is_complete=0).all()

q3 = Task.query.filter_by(time_quad=3).filter_by(user_id=currentUser).filter_by(is_complete=0).all()

q4 = Task.query.filter_by(time_quad=4).filter_by(user_id=currentUser).filter_by(is_complete=0).all()

taskAll = q1 + q2 + q3 + q4


print("current user" + str(currentUser))


return render_template('schedule.html', taskList = taskAll)

ERROR 错误

Exception on /schedule [GET]
Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
    context)
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 509, in do_execute
    cursor.execute(statement, parameters)
psycopg2.ProgrammingError: operator does not exist: boolean = integer
LINE 3: ....time_quad = 1 AND task.user_id = 1 AND task.is_complete = 0


HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
 [SQL: 'SELECT task.id AS task_id, task.name AS task_name, task.description AS task_description, task.priority AS task_priority, task.is_complete AS task_is_complete, task.url AS task_url, task.est_dur AS task_est_dur, task.time_quad AS task_time_quad, task.timestamp AS task_timestamp, task.user_id AS task_user_id \nFROM task \nWHERE task.time_quad = %(time_quad_1)s AND task.user_id = %(user_id_1)s AND task.is_complete = %(is_complete_1)s'] [parameters: {'time_quad_1': 1, 'user_id_1': 1, 'is_complete_1': 0}] (Background on this error at: http://sqlalche.me/e/f405)

PostgreSQL has a real boolean type but SQLite doesn't, SQLite generally uses one and zero for true and false (respectively). PostgreSQL有一个真正的布尔类型,但是SQLite没有,SQLite通常分别使用true和false分别为1和0。 When you say this: 当你这样说:

filter_by(is_complete=0)

the 0 will be interpreted by SQLite as "false" but by PostgreSQL as just the number zero; SQLite将0解释为“ false”,而PostgreSQL仅将其解释为数字0; hence the complaint at Heroku about not being able to compare a boolean and an integer in task.is_complete = 0 . 因此Heroku抱怨无法在task.is_complete = 0比较布尔值和整数。 If you mean "false", say so: 如果您的意思是“假”,请这样说:

filter_by(is_complete=False)

That should be converted to zero when talking to SQLite and the proper boolean 'f' (or false ) when talking to PostgreSQL. 在与SQLite对话时,应将其转换为零;在与PostgreSQL对话时,应将其转换为正确的布尔值'f' (或false )。

Once you fix that, I strongly recommend that you install PostgreSQL in your development environment if that's the database you're going to be deploying on. 解决此问题后,强烈建议您在要在其上部署数据库的开发环境中安装PostgreSQL。 You'll have a much better time of things if you develop, test, and deploy on the same stack. 如果您在同一堆栈上进行开发,测试和部署,那么您的工作时间将大大缩短。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM