简体   繁体   English

sqlalchemy.exc.DataError: (psycopg2.errors.InvalidTextRepresentation) 类型 integer 的输入语法无效:“无”

[英]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.

相关问题 sqlalchemy.exc.DataError: (psycopg2.errors.InvalidTextRepresentation) 类型 integer 的无效输入语法:“B1” - sqlalchemy.exc.DataError: (psycopg2.errors.InvalidTextRepresentation) invalid input syntax for type integer: "B1" Flask 和 Postgresql - sqlalchemy.exc.DataError: (psycopg2.errors.InvalidTextRepresentation) 枚举的无效输入值 - Flask and Postgresql - sqlalchemy.exc.DataError: (psycopg2.errors.InvalidTextRepresentation) invalid input value for enum 如何修复 sqlalchemy.exc.DataError: (psycopg2.errors.StringDataRightTruncation)? - How to fix sqlalchemy.exc.DataError: (psycopg2.errors.StringDataRightTruncation)? sqlalchemy.exc.DataError: (psycopg2.errors.StringDataRightTruncation) 类型字符变化的值太长 (256) - sqlalchemy.exc.DataError: (psycopg2.errors.StringDataRightTruncation) value too long for type character varying(256) psycopg2.errors.InvalidTextRepresentation - psycopg2.errors.InvalidTextRepresentation sqlalchemy.exc.DataError: (psycopg2.DataError) 值对于不同的类型字符来说太长了 - sqlalchemy.exc.DataError: (psycopg2.DataError) value too long for type character varying sqlalchemy.exc.DataError:(psycopg2.DataError)值太长,无法更改类型字符(20) - sqlalchemy.exc.DataError: (psycopg2.DataError) value too long for type character varying(20) DataError:(psycopg2.DataError)整数的无效输入语法 - DataError: (psycopg2.DataError) invalid input syntax for integer 在PostgreSQL中执行更新查询时出现sqlalchemy.exc.DataError - sqlalchemy.exc.DataError while executing the update query in Postgresql (psycopg2.DataError) 整数的无效输入语法:从 csv 文件导入? - (psycopg2.DataError) invalid input syntax for integer: importing from csv file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM