Answer the question
In order to leave comments, you need to log in
PostgreSQL not working id autoincrement?
Updated the database and now an error occurs when trying to insert a new record into the `user_artist` table.
create table user_artist
(
"id" serial primary key,
"userId" serial REFERENCES user (id) on delete cascade,
"artistId" serial REFERENCES artist (id) on delete cascade,
"added" timestamp,
unique ("userId", "artistId")
);
{ error: нулевое значение в столбце "id" нарушает ограничение NOT NULL
0|index | at Connection.parseE (/home/www.example.com/node_modules/pg/lib/connection.js:553:11)
0|index | at Connection.parseMessage (/home/www.example.com/node_modules/pg/lib/connection.js:378:19)
0|index | at Socket.<anonymous> (/home/www.example.com/node_modules/pg/lib/connection.js:119:22)
0|index | at Socket.emit (events.js:182:13)
0|index | at Socket.EventEmitter.emit (domain.js:442:20)
0|index | at addChunk (_stream_readable.js:280:12)
0|index | at readableAddChunk (_stream_readable.js:265:11)
0|index | at Socket.Readable.push (_stream_readable.js:220:10)
0|index | at TCP.onread (net.js:638:20)
0|index | name: 'error',
0|index | length: 293,
0|index | severity: 'ОШИБКА',
0|index | code: '23502',
0|index | detail: 'Ошибочная строка содержит (null, 1, 725142, 2018-09-01 12:22:55).',
0|index | hint: undefined,
0|index | position: undefined,
0|index | internalPosition: undefined,
0|index | internalQuery: undefined,
0|index | where: undefined,
0|index | schema: 'public',
0|index | table: 'user_artist',
0|index | column: 'id',
0|index | dataType: undefined,
0|index | constraint: undefined,
0|index | file: 'execMain.c',
0|index | line: '2008',
0|index | routine: 'ExecConstraints' }
INSERT INTO user_artist ("userId", "artistId", added) VALUES ($(userId), $(artistId), $(added))
ON CONFLICT DO NOTHING;
Answer the question
In order to leave comments, you need to log in
The request sends 3 values, and the message has 4 elements, perhaps the ORM intervenes?
Try explicitly setting the id so that the request looks like this:
INSERT INTO user_artist (id, "userId", "artistId", added)
VALUES (default, $(userId), $(artistId), $(added))
ON CONFLICT DO NOTHING;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question