如何在 SQLAlchemy 中插入 NULL 值? [英] How to insert NULL value in SQLAlchemy?

查看:23
本文介绍了如何在 SQLAlchemy 中插入 NULL 值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有以下列的 Table:

I've a Table with the following column:

Column('type', String(128))

如何在数据库中插入新行时将此列设置为 NULL?

How do I set this column to NULL when inserting a new row in database?

我尝试这样做:

self.type = NULL;

Python 中没有 NULL 类型,所以我不知道该怎么做.

There is no NULL type in Python so I don't know how to do it.

推荐答案

而不是尝试

self.type = NULL

按照雅罗斯拉夫管理员的建议尝试

self.type = None

因为 Python 对 NULL 的等价物是 None.

As Python's equivalent for NULL is None.

这篇关于如何在 SQLAlchemy 中插入 NULL 值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆