Reputation: 99
I am developing the Web Application in Flask built on top of Docker images. One image stores the Postgres Database. I am struggling with inserting None
into the Integer column defined followingly:
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:
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?
Thank you for any help.
Upvotes: 1
Views: 1393
Reputation: 99
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; however, "None" was the value of the select. I missed that. It seems that the issue is solved.
Upvotes: 1