Error in `migrate` command: `PostgresError: no schema has been selected to create in`

bunx drizzle-kit migrate
No config path provided, using default 'drizzle.config.ts'
Reading config file '/Users/ftzi/dev/main-nextstack-website/drizzle.config.ts'
postgresql://neondb_owner:DkIm2cK9NiCe@ep-raspy-math-a2mlj10n-pooler.eu-central-1.aws.neon.tech/neondb?sslmode=require
Using 'postgres' driver for database querying
[⣟] applying migrations...PostgresError: no schema has been selected to create in
at ErrorResponse (file:///Users/ftzi/dev/main-nextstack-website/node_modules/postgres/src/connection.js:788:26)
at handle (file:///Users/ftzi/dev/main-nextstack-website/node_modules/postgres/src/connection.js:474:6)
at TLSSocket.data (file:///Users/ftzi/dev/main-nextstack-website/node_modules/postgres/src/connection.js:315:9)
at TLSSocket.emit (node:events:518:28)
at addChunk (node:internal/streams/readable:561:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Readable.push (node:internal/streams/readable:392:5)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:189:23) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '3F000',
position: '14',
file: 'namespace.c',
line: '702',
routine: 'RangeVarGetCreationNamespace'
}
bunx drizzle-kit migrate
No config path provided, using default 'drizzle.config.ts'
Reading config file '/Users/ftzi/dev/main-nextstack-website/drizzle.config.ts'
postgresql://neondb_owner:DkIm2cK9NiCe@ep-raspy-math-a2mlj10n-pooler.eu-central-1.aws.neon.tech/neondb?sslmode=require
Using 'postgres' driver for database querying
[⣟] applying migrations...PostgresError: no schema has been selected to create in
at ErrorResponse (file:///Users/ftzi/dev/main-nextstack-website/node_modules/postgres/src/connection.js:788:26)
at handle (file:///Users/ftzi/dev/main-nextstack-website/node_modules/postgres/src/connection.js:474:6)
at TLSSocket.data (file:///Users/ftzi/dev/main-nextstack-website/node_modules/postgres/src/connection.js:315:9)
at TLSSocket.emit (node:events:518:28)
at addChunk (node:internal/streams/readable:561:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Readable.push (node:internal/streams/readable:392:5)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:189:23) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '3F000',
position: '14',
file: 'namespace.c',
line: '702',
routine: 'RangeVarGetCreationNamespace'
}
My config. If I console.log something there, it's properly printed when the command above is run.
import type { Config } from "drizzle-kit";

export default {
schema: "./src/server/db/schema",
dialect: "postgresql",

dbCredentials: {
url: process.env.DATABASE_URL ?? "MISSING",
},

migrations: {
table: "__drizzle_migrations",
schema: "drizzle",
},
} satisfies Config;
import type { Config } from "drizzle-kit";

export default {
schema: "./src/server/db/schema",
dialect: "postgresql",

dbCredentials: {
url: process.env.DATABASE_URL ?? "MISSING",
},

migrations: {
table: "__drizzle_migrations",
schema: "drizzle",
},
} satisfies Config;
2 Replies
Bruno
BrunoOP3d ago
Adding CREATE SCHEMA IF NOT EXISTS "public"; to the top of the migration file works. https://github.com/drizzle-team/drizzle-orm/discussions/516#discussioncomment-10094540
GitHub
error - unhandledRejection: error: no schema has been selected to c...
Using pg-core with "drizzle-orm": "^0.25.2", and my following db.ts looks like the following: // db.ts import { drizzle } from "drizzle-orm/node-postgres"; import { mi...
Bruno
BrunoOP3d ago
How can I automate this creation?

Did you find this page helpful?