EF WPF - 列" ContractID"中的空值违反非空约束

时间:2018-03-29 00:56:02

标签: c# postgresql entity-framework

我正在使用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;

当我尝试向表中添加一行时,我得到一个例外:

enter image description here

我的合同类:

enter image description here

我尝试了很多东西,但我真的不明白为什么会这样。

请帮助理解为什么我会收到此例外。

1 个答案:

答案 0 :(得分:1)

尝试将ContactId的值更改为serial而不是integer。就我所见,您没有向列ContactId添加任何值,因此默认情况下它为空

希望这会有所帮助:)。如果答案没有帮助,请务必在downvoting之前发表评论:)