Heroku和Postgres的Flask SQLAlchemy错误psycopg2.errors.DatatypeMismatch

如何解决Heroku和Postgres的Flask SQLAlchemy错误psycopg2.errors.DatatypeMismatch

我已经用Heroku安装了我的Python应用程序,并且正在从我的SQLite数据库迁移到Postgres数据库。但是,我遇到了SQLite不会发生的以下错误:

sqlalchemy.exc.ProgrammingError: (psycopg2.errors.DatatypeMismatch) argument of WHERE must be type boolean,not type character varying
LINE 3: WHERE site_clearance."CreatedOn"
              ^

[SQL: SELECT id 
FROM site_clearance 
WHERE site_clearance."CreatedOn"]
(Background on this error at: http://sqlalche.me/e/f405)

该查询的相应Python代码用于生成PDF文件,而该查询正在生成错误:

# MAKE THE DB QUERIES HERE THAT ARE NEEDED TO BE ENTERED INTO EACH RECORD SHEET
for i in range(0,len(dictionary)):
    query = [r[0] for r in db.session.query(model).filter(model.CreatedOn).values(keys[i])]
    queries.append(query)

正如我所说,SQLite不会发生此错误,而麻烦是从psycopg2软件包开始的。来自以下服务器日志的堆栈跟踪。任何帮助表示赞赏。谢谢!

2020-08-10T17:54:25.630676+00:00 heroku[router]: at=info method=GET path="/makepdf_site_clearance" host=hidden-meadow-44024.herokuapp.com request_id=6bb8550d-afd0-415f-9e8b-bf0a86e63ab4 fwd="88.98.244.118" dyno=web.1 connect=1ms service=37ms status=500 bytes=484 protocol=https
2020-08-10T17:54:25.627181+00:00 app[web.1]: [2020-08-10 17:54:25,620] ERROR in app: Exception on /makepdf_site_clearance [GET]
2020-08-10T17:54:25.627193+00:00 app[web.1]: Traceback (most recent call last):
2020-08-10T17:54:25.627194+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/base.py",line 1284,in _execute_context
2020-08-10T17:54:25.627194+00:00 app[web.1]: cursor,statement,parameters,context
2020-08-10T17:54:25.627195+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/default.py",line 590,in do_execute
2020-08-10T17:54:25.627196+00:00 app[web.1]: cursor.execute(statement,parameters)
2020-08-10T17:54:25.627196+00:00 app[web.1]: psycopg2.errors.DatatypeMismatch: argument of WHERE must be type boolean,not type character varying
2020-08-10T17:54:25.627196+00:00 app[web.1]: LINE 3: WHERE site_clearance."CreatedOn"
2020-08-10T17:54:25.627197+00:00 app[web.1]: ^
2020-08-10T17:54:25.627198+00:00 app[web.1]:
2020-08-10T17:54:25.627198+00:00 app[web.1]:
2020-08-10T17:54:25.627199+00:00 app[web.1]: The above exception was the direct cause of the following exception:
2020-08-10T17:54:25.627199+00:00 app[web.1]:
2020-08-10T17:54:25.627200+00:00 app[web.1]: Traceback (most recent call last):
2020-08-10T17:54:25.627200+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py",line 2447,in wsgi_app
2020-08-10T17:54:25.627201+00:00 app[web.1]: response = self.full_dispatch_request()
2020-08-10T17:54:25.627201+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py",line 1952,in full_dispatch_request
2020-08-10T17:54:25.627202+00:00 app[web.1]: rv = self.handle_user_exception(e)
2020-08-10T17:54:25.627202+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py",line 1821,in handle_user_exception
2020-08-10T17:54:25.627203+00:00 app[web.1]: reraise(exc_type,exc_value,tb)
2020-08-10T17:54:25.627203+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py",line 39,in reraise
2020-08-10T17:54:25.627203+00:00 app[web.1]: raise value
2020-08-10T17:54:25.627204+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py",line 1950,in full_dispatch_request
2020-08-10T17:54:25.627204+00:00 app[web.1]: rv = self.dispatch_request()
2020-08-10T17:54:25.627205+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py",line 1936,in dispatch_request
2020-08-10T17:54:25.627205+00:00 app[web.1]: return self.view_functions[rule.endpoint](**req.view_args)
2020-08-10T17:54:25.627206+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask_login/utils.py",line 272,in decorated_view
2020-08-10T17:54:25.627206+00:00 app[web.1]: return func(*args,**kwargs)
2020-08-10T17:54:25.627207+00:00 app[web.1]: File "/app/constructaerp02/routes.py",line 1191,in makepdf_site_clearance
2020-08-10T17:54:25.627207+00:00 app[web.1]: p = pdf_make(model=SiteClearance,dictionary=SiteClearance_dictionary,title='Site Clearance')
2020-08-10T17:54:25.627208+00:00 app[web.1]: File "/app/constructaerp02/pdf_creator.py",line 23,in pdf_make
2020-08-10T17:54:25.627208+00:00 app[web.1]: query = [r[0] for r in db.session.query(model).filter(model.CreatedOn).values(keys[i])]
2020-08-10T17:54:25.627209+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/orm/query.py",line 1530,in values
2020-08-10T17:54:25.627209+00:00 app[web.1]: return iter(q)
2020-08-10T17:54:25.627210+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/orm/query.py",line 3481,in __iter__
2020-08-10T17:54:25.627210+00:00 app[web.1]: return self._execute_and_instances(context)
2020-08-10T17:54:25.627211+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/orm/query.py",line 3506,in _execute_and_instances
2020-08-10T17:54:25.627211+00:00 app[web.1]: result = conn.execute(querycontext.statement,self._params)
2020-08-10T17:54:25.627212+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/base.py",line 1020,in execute
2020-08-10T17:54:25.627212+00:00 app[web.1]: return meth(self,multiparams,params)
2020-08-10T17:54:25.627212+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/sql/elements.py",line 298,in _execute_on_connection
2020-08-10T17:54:25.627213+00:00 app[web.1]: return connection._execute_clauseelement(self,params)
2020-08-10T17:54:25.627213+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/base.py",line 1139,in _execute_clauseelement
2020-08-10T17:54:25.627214+00:00 app[web.1]: distilled_params,2020-08-10T17:54:25.627215+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/base.py",line 1324,in _execute_context
2020-08-10T17:54:25.627215+00:00 app[web.1]: e,cursor,context
2020-08-10T17:54:25.627216+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/base.py",line 1518,in _handle_dbapi_exception
2020-08-10T17:54:25.627216+00:00 app[web.1]: sqlalchemy_exception,with_traceback=exc_info[2],from_=e
2020-08-10T17:54:25.627216+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/util/compat.py",line 178,in raise_
2020-08-10T17:54:25.627217+00:00 app[web.1]: raise exception
2020-08-10T17:54:25.627217+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/base.py",in _execute_context
2020-08-10T17:54:25.627218+00:00 app[web.1]: cursor,context
2020-08-10T17:54:25.627218+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/default.py",in do_execute
2020-08-10T17:54:25.627219+00:00 app[web.1]: cursor.execute(statement,parameters)
2020-08-10T17:54:25.627223+00:00 app[web.1]: sqlalchemy.exc.ProgrammingError: (psycopg2.errors.DatatypeMismatch) argument of WHERE must be type boolean,not type character varying
2020-08-10T17:54:25.627224+00:00 app[web.1]: LINE 3: WHERE site_clearance."CreatedOn"
2020-08-10T17:54:25.627224+00:00 app[web.1]: ^
2020-08-10T17:54:25.627224+00:00 app[web.1]:
2020-08-10T17:54:25.627225+00:00 app[web.1]: [SQL: SELECT id
2020-08-10T17:54:25.627225+00:00 app[web.1]: FROM site_clearance
2020-08-10T17:54:25.627226+00:00 app[web.1]: WHERE site_clearance."CreatedOn"]
2020-08-10T17:54:25.627233+00:00 app[web.1]: (Background on this error at: http://sqlalche.me/e/f405)
2020-08-10T17:54:25.631141+00:00 app[web.1]: 10.63.174.10 - - [10/Aug/2020:17:54:25 +0000] "GET 

解决方法

错误确切说明了正在发生的事情;您正在使用QGraphicsBlurEffect *effect = new QGraphicsBlurEffect(this); effect->setBlurRadius(100); QRadialGradient grad(QPoint(50,50),50); grad.setSpread(QGradient::RepeatSpread); grad.setColorAt(0,QColor(0,0)); grad.setColorAt(1,QColor(100,100,100)); QGraphicsRectItem *item = new QGraphicsRectItem(0,100); item->setBrush(QBrush(grad)); item->setGraphicsEffect(effect); ,但是.filter(model.createdOn)是什么?

一个选项是createdOn会起作用,因为它会生成SQL .filter(model.createdOn > datetime.now() - timedelta(days=7))或类似的东西。

另一种选择是"createdOn" > "2020-08-03 12:00:00".filter(model.createdOn.isnot(None)),两者都会生成.filter(~model.createdOn.is_(None))

在这种情况下,通常最好打印查询,为变量输入一些虚拟值,然后查看是否在直接执行SQL的情况下运行。这对调试很有帮助!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-