NHibernate not-null 属性无效

发布于 2024-09-08 16:11:41 字数 512 浏览 2 评论 0原文

我正在尝试向现有表添加一列。我向映射添加了一个属性:

<property name="SelectionId" column="selection_id" not-null="true"/>

当我打开会话时,会创建新列,但是不考虑 not-null 属性:新列可为空。

我意识到您需要在添加不可为 null 的列时指定默认值,但是 没有 defaultdefault-value 属性。 元素...无论如何,我不想要此列上的默认值:我想在现有行上为其设置特定值 (0),但后续插入将必须明确指定该值。

我怎样才能让它发挥作用?我必须在 SQL 中手动执行此操作吗?

顺便说一句,底层的 DBMS 是 SQLite,它对 ALTER TABLE 的支持非常有限(仅支持添加列和重命名表)...

I'm trying to add a column to an existing table. I added a property to the mapping :

<property name="SelectionId" column="selection_id" not-null="true"/>

When I open the session, the new column is created, however the not-null attribute is not taken into account : the new column is nullable.

I realize you need to specify a default value when adding a non-nullable column, but there is no default or default-value attribute for the <property> element... And anyway, I don't want a default value on this column : I want to set a specific value (0) for it on existing rows, but subsequent inserts will have to specify the value explicitly.

How can I make it work ? Do I have to do it manually in SQL ?

BTW, the underlying DBMS is SQLite, which has very limited support for ALTER TABLE (only add column and rename table are supported)...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文