PostgreSQL:非空冲突:7错误:列“中的值为空”;id";违反非空约束 教条 acme\u搜索\u项目表 acme\u搜索\u项目\u id\u序列 SQL 编辑 问题:
我使用了PostgreSQL:非空冲突:7错误:列“中的值为空”;id";违反非空约束 教条 acme\u搜索\u项目表 acme\u搜索\u项目\u id\u序列 SQL 编辑 问题:,postgresql,doctrine,dbal,Postgresql,Doctrine,Dbal,我使用了DEFAULT关键字,它应该是下一个id,但是正如您所看到的,它是错误的。我正在使用PostgreSQL 10.4。我发现没有定义extval('*\u id\u seq'::regclass)。我使用原则来定义上述数据库结构,如文档所述。确保您的id列具有默认值: ALTER TABLE acme_search_item ALTER COLUMN id SET DEFAULT nextval('acme_search_item_id_seq'); 您可以在信息架构表中查看当前
DEFAULT
关键字,它应该是下一个id,但是正如您所看到的,它是错误的。我正在使用PostgreSQL 10.4。我发现没有定义extval('*\u id\u seq'::regclass)
。我使用原则来定义上述数据库结构,如文档所述。确保您的id
列具有默认值:
ALTER TABLE acme_search_item
ALTER COLUMN id SET DEFAULT nextval('acme_search_item_id_seq');
您可以在信息架构表中查看当前默认值:
SELECT column_name
, column_default
FROM information_schema.columns
WHERE table_name = 'acme_search_item'
ORDER BY
ordinal_position;
我明白了,谢谢你帮我定位这个问题,我找到了一个类似的,它解决了这个问题。你知道为什么这个错误会突然出现吗?我的表以前从来没有IDs的默认值,它工作得很好,但突然我的一个环境因为这个原因停止了插入。无论如何,定义默认值本身就是一个好主意。
acme_test=# \d acme_search_item_id_seq
Sequence "public.acme_search_item_id_seq"
Type | Start | Minimum | Maximum | Increment | Cycles? | Cache
--------+-------+---------+---------------------+-----------+---------+-------
bigint | 1 | 1 | 9223372036854775807 | 1 | no | 1
acme_test=# INSERT INTO acme_search_item (id,entity,ALIAS,record_id,title,weight,changed,created_at,updated_at) VALUES (DEFAULT,'Pintushi\\Bundle\\OrganizationBundle\\Entity\\Organization','acme_organization','1','tt','1','0','2019-03-18 17:15:57','2019-03-18 17:15:57');
ERROR: null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, Acme\\Bundle\\OrganizationBundle\\Entity\\Organization, acme_organization, 1, tt, 1.00000000, f, 2019-03-18 17:15:57, 2019-03-18 17:15:57).
acme_test=# INSERT INTO acme_search_item (id,entity,ALIAS,record_id,title,weight,changed,created_at,updated_at) VALUES (1,'Acme\\Bundle\\OrganizationBundle\\Entity\\Organization','acme_organization','1','tt','1','0','2019-03-18 17:15:57','2019-03-18 17:15:57');
INSERT 0 1
acme_test=# INSERT INTO acme_search_item (entity,ALIAS,record_id,title,weight,changed,created_at,updated_at) VALUES ('Acme\\Bundle\\OrganizationBundle\\Entity\\Organization','acme_organization','1','tt','1','0','2019-03-18 17:15:57','2019-03-18 17:15:57');;
ERROR: null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, Acme\\Bundle\\OrganizationBundle\\Entity\\Organization, acme_organization, 1, tt, 1.00000000, f, 2019-03-18 17:15:57, 2019-03-18 17:15:57).
ALTER TABLE acme_search_item
ALTER COLUMN id SET DEFAULT nextval('acme_search_item_id_seq');
SELECT column_name
, column_default
FROM information_schema.columns
WHERE table_name = 'acme_search_item'
ORDER BY
ordinal_position;