npm pg: Postgre error: Could not connect to databasefunction uuid_generate_v4() does not exist
While inserting a user into the user table using npm pg module, but getting following error
error: Could not connect to databasefunction uuid_generate_v4() does not exist {"name":"QueryFailedError","length":207,"severity":"ERROR","code":"42883","hint":"No function matches the given name and argument types. You might need to add explicit type casts.","file":"parse_func.c","line":"621","routine":"ParseFuncOrColumn","query":"CREATE TABLE \"user\" (\"uuid\" uuid NOT NULL DEFAULT uuid_generate_v4(), \"auth0ID\" character varying, \"firstName\" character varying NOT NULL, \"lastName\" character varying NOT NULL, \"email\" character varying NOT NULL, \"phone\" character varying, \"entityType\" character varying NOT NULL, \"lastActiveAt\" TIMESTAMP, \"deletedAt\" TIMESTAMP, \"createdAt\" TIMESTAMP NOT NULL DEFAULT now(), \"updatedAt\" TIMESTAMP NOT NULL DEFAULT now(), \"isArmadaAgent\" boolean, \"isSuperUser\" boolean, CONSTRAINT \"PK_a95e949168be7b7ece1a2382fed\" PRIMARY KEY (\"uuid\"))","parameters":[],"stack":"QueryFailedError: function uuid_generate_v4() does not exist\n at new QueryFailedError (/Users/experimantal/githome/foo/src/error/QueryFailedError.ts:9:9)\n at Query.callback (/Users/experimantal/githome/foo/src/driver/postgres/PostgresQueryRunner.ts:178:30)\n at Query.handleError (/Users/experimantal/githome/foo/node_modules/pg/lib/query.js:142:17)\n at Connection.connectedErrorMessageHandler (/Users/experimantal/githome/foo/node_modules/pg/lib/client.js:211:17)\n at Connection.emit (events.js:182:13)\n at Socket.<anonymous> (/Users/experimantal/githome/foo/node_modules/pg/lib/connection.js:126:12)\n at Socket.emit (events.js:182:13)\n at addChunk (_stream_readable.js:283:12)\n at readableAddChunk (_stream_readable.js:264:11)\n at Socket.Readable.push (_stream_readable.js:219:10)\n at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)"}
(node:15812) UnhandledPromiseRejectionWarning: QueryFailedError: function uuid_generate_v4() does not exist
1 Answer
5 years ago by Eleven
create uuid-ossp
extension first then retry.
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
5 years ago by Karthik Divi