无法将数据插入Postgresql约束检查

时间:2019-06-07 09:37:32

标签: postgresql constraints

我尝试如下将数据插入表中

CREATE TABLE account.companies
(
    id bigint NOT NULL DEFAULT nextval('account.companies_id_seq'::regclass),
    account_id bigint NOT NULL DEFAULT nextval('account.companies_account_id_seq'::regclass),
    status character varying(12) COLLATE pg_catalog."default" NOT NULL,
    account_type character varying(10) COLLATE pg_catalog."default" NOT NULL,
    created_at timestamp without time zone NOT NULL,
    updated_at timestamp without time zone,
    CONSTRAINT companies_pkey PRIMARY KEY (id),
    CONSTRAINT companies_account_id_fkey FOREIGN KEY (account_id)
        REFERENCES account.accounts (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT status_check CHECK (status::text = 'SUBMITTED'::text OR status::text = 'PENDING'::text OR status::text = 'ACTION_REQ'::text OR status::text = 'PASS'::text OR status::text = 'FAIL'::text),
    CONSTRAINT account_type_check CHECK (status::text = 'INDIVIDUAL'::text OR status::text = 'COMPANY'::text)
)

从pgadmin4插入记录和错误

应该能够插入数据

1 个答案:

答案 0 :(得分:0)

找到答案..it来自旧文件 新文件已更正

CONSTRAINT account_type_check CHECK (account_type::text = 'INDIVIDUAL'::text OR account_type::text = 'COMPANY'::text)