【发布时间】:2018-11-25 10:56:26
【问题描述】:
我遇到了这个 DBUnit 问题,导致 SQL 插入错误。假设我的 dbunit testdata.xml 文件中有这个:
<myschema.mytable id="1" value1="blah" value2="foo" />
我有一张这样的表(postgres)
myschema.mytable 有一个 id、value1、value2 和一个日期字段,比如“lastmodified”。 lastmodified 列是带有修饰符“not null default now()”的时间戳
似乎 dbunit 读取表元数据并尝试为我的 testdata.xml 文件中未指定的任何列插入空值。所以上面的 xml 会产生这样的插入:
insert into myschema.mytable (id,value1,value2,lastmodified) values (1,'blah','foo',null)
运行测试时(dbunit/maven 插件)我收到如下错误:
Error executing database operation: REFRESH: org.postgresql.util.PSQLException: ERROR: null value in column "lastmodified" violates not-null constraint
有没有办法告诉 DBUnit 不要在我没有指定的字段上插入空值?
编辑:使用 dbunit 2.5.3、junit 4.12、postgressql 驱动程序 9.4.1208
【问题讨论】:
标签: database postgresql junit4 dbunit spring-test-dbunit