我正在使用Entity Framework 6.0.0 + Npgsql + Npgsql.EntityFramework,我在调用SaveChanges
时遇到PostgreSQL错误:
列中的空值" ContractID"违反了非空约束"
以下是我在数据库中使用的表格:
CREATE TABLE public."Contracts"
(
"ContractID" integer NOT NULL,
"Visits" integer,
"ClientID" integer NOT NULL,
"Price" money,
"SigningDate" date
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public."Contracts"
OWNER to postgres;
当我尝试向表中添加一行时,我得到一个例外:
我的合同类:
我尝试了很多东西,但我真的不明白为什么会这样。
请帮助理解为什么我会收到此例外。
答案 0 :(得分:1)
尝试将ContactId
的值更改为serial
而不是integer
。就我所见,您没有向列ContactId
添加任何值,因此默认情况下它为空
希望这会有所帮助:)。如果答案没有帮助,请务必在downvoting之前发表评论:)