[英]sqlalchemy.exc.DataError: (psycopg2.errors.InvalidTextRepresentation) invalid input syntax for type integer: "None"
I am developing the Web Application in Flask built on top of Docker images.我正在 Docker 图像之上构建 Flask 中的 Web 应用程序。 One image stores the Postgres Database.
一张图片存储 Postgres 数据库。 I am struggling with inserting
None
into the Integer column defined followingly:我正在努力将
None
插入 Integer 列定义如下:
release = db.Column(db.Integer, nullable=True)
Row initialization:行初始化:
def __init__(self, name: str, env: str, mode: ExecutionMode, status: ExecutionStatus, date: datetime, user_id: int,
release_id: int):
self.execution_name = name
self.environment = env
self.execution_mode = mode
self.execution_status = status
self.execution_date = date
self.user_id = user_id
self.release = release_id
db.session.add(self)
db.session.commit()
Caller's method:调用方方法:
if request.method == "POST":
execution = Execution(name=data['result']['name'], env=Environment[data['result']['env']],
mode=ExecutionMode[data['result']['mode']],
status=ExecutionStatus[data['result']['status']],
date=datetime.datetime.strptime(data['result']['date'], "%Y-%m-%d %H:%M:%S.%f"),
user_id=current_user.id,
release_id=(data['result']['release'] if data['result'][
'release'] != "null" else sqlalchemy.null()))
Whenever I encounter the case, that the value of the Release is None
, the following exception is triggered:每当我遇到 Release 的值为
None
的情况时,都会触发以下异常:
sqlalchemy.exc.DataError: (psycopg2.errors.InvalidTextRepresentation) invalid input syntax for type integer: "None"
Does anyone know, how to insert the None
respectively NULL
value into the database?有谁知道,如何将
None
分别插入NULL
值到数据库中?
Thank you for any help.感谢您的任何帮助。
The problem is actually on the front-end in the form that accepts the data.问题实际上出在接受数据的表单的前端。 There was supposed to be the value of "null" in the select box;
select 框中应该有“null”值; however, "None" was the value of the select.
但是,“无”是 select 的值。 I missed that.
我错过了。 It seems that the issue is solved.
看来问题已经解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.