NHibernate not-null 属性无效
我正在尝试向现有表添加一列。我向映射添加了一个属性:
<property name="SelectionId" column="selection_id" not-null="true"/>
当我打开会话时,会创建新列,但是不考虑 not-null
属性:新列可为空。
我意识到您需要在添加不可为 null 的列时指定默认值,但是
元素...无论如何,我不想要此列上的默认值:我想在现有行上为其设置特定值 (0),但后续插入将必须明确指定该值。default
或 default-value
属性。
我怎样才能让它发挥作用?我必须在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论