Łuk*_*iak 4 postgresql constraint postgresql-9.6
该关系是在 Postgres 9.6 中使用以下命令创建的:
CREATE TABLE import_event (
import_event_id BIGINT NOT NULL,
filename VARCHAR (200) CONSTRAINT NN_import_event__filename NOT NULL
);
ALTER TABLE ONLY import_event ADD CONSTRAINT PK_import_cak_key PRIMARY KEY (import_event_id);
Run Code Online (Sandbox Code Playgroud)
请注意,not null 约束已命名。
然后执行了下面的命令
insert into import_event (import_event_id) values (1);
Run Code Online (Sandbox Code Playgroud)
当然,约束违反错误被提出。消息内容如下
ERROR: null value in column "filename" violates not-null constraint
DETAIL: Failing row contains (1, null).**strong text**
Run Code Online (Sandbox Code Playgroud)
问题是该消息中缺少非空约束的名称。但是,正确的错误消息:
ERROR: new row for relation "import_event" violates check constraint "nn_import_event__filename"
Run Code Online (Sandbox Code Playgroud)
当非空约束声明如下时产生
ALTER TABLE ONLY import_event ADD CONSTRAINT NN_import_event__filename CHECK(filename IS NOT NULL);
Run Code Online (Sandbox Code Playgroud)
这是 Postgres 9.6 中的错误还是约束声明有问题?
归档时间: |
|
查看次数: |
1076 次 |
最近记录: |