首页 > 解决方案 > 为什么重新生成的 Postgres 表会在 Vapor 中引发错误?

问题描述

生产环境中的表是这样创建的:

-- DDL generated by Postico 1.5.10
-- Not all database features are supported. Do not use for backup.

-- Table Definition ----------------------------------------------

CREATE TABLE "TempUser" (
    id bigint PRIMARY KEY,
    "Uuid" text NOT NULL,
    "dateCreated" timestamp without time zone NOT NULL,
    "lastRequestDate" timestamp without time zone NOT NULL,
    "lastRequestLocation" text,
    "numOfRequest" bigint NOT NULL,
    comment text NOT NULL,
    "lastRequestDescription" text NOT NULL,
    "bookedSeats" text NOT NULL,
    "bookUntil" timestamp without time zone,
    "lastEventVisited" text
);

-- Indices -------------------------------------------------------

CREATE UNIQUE INDEX "pk:TempUser.id" ON "TempUser"(id int8_ops);

为什么我在dev环境中删除表并在 Postgres 控制台中创建这样的表,尝试以编程方式编写后出现以下错误:

[ ERROR ] PostgreSQLError.server.error.ExecConstraints: POST /registerTempUser null value in column "id" violates not-null constraint (ErrorMiddleware.swift:26)
[ DEBUG ] Possible causes for PostgreSQLError.server.error.ExecConstraints: Failing row contains (null, 015574220836500, 2020-07-09 19:42:36.803846, 2020-07-09 19:42:36.803846, null, 1, , POST /registerTempUser HTTP/1.1
Host: localhost:8080
Content-Typ..., [], null, null). (ErrorMiddleware.swift:26)

为什么,怎么了?

尝试设置序列的东西:

 select setval(pg_get_serial_sequence('"TempUser"', 'id'), 1);
 select currval(pg_get_serial_sequence('"TempUser"', 'id'));

没有改变。

标签: postgresqlvapor

解决方案


推荐阅读