Karl
Karl
DTDrizzle Team
Created by Karl on 9/4/2024 in #help
Error when attempting to migrate on Windows
Hey, I am working on a project which uses Next.js, TypeScript and Drizzle, I'm running a local, freshly installed Postgres server on my machine, in which I have created a database and granted all permissions for it to user postgres. I am getting a connection URL from the environment variables (specified in a .env.local file) in the following format: postgres://postgres:postgres@127.0.0.1:5432/<db_name>. The error I'm getting is this:
Migration failed: Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string
at <path_to_project>\node_modules\pg-pool\index.js:45:11
at processTicksAndRejections (node:internal/process/task_queues:105:5)
at async PgDialect.migrate (<path_to_project>\node_modules\src\pg-core\dialect.ts:72:3)
at async migrate (<path_to_project>\node_modules\src\node-postgres\migrator.ts:10:2)
at async runMigration (<path_to_project>\src\migration\migrate.ts:9:5)
Database connection closed
Migration failed: Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string
at <path_to_project>\node_modules\pg-pool\index.js:45:11
at processTicksAndRejections (node:internal/process/task_queues:105:5)
at async PgDialect.migrate (<path_to_project>\node_modules\src\pg-core\dialect.ts:72:3)
at async migrate (<path_to_project>\node_modules\src\node-postgres\migrator.ts:10:2)
at async runMigration (<path_to_project>\src\migration\migrate.ts:9:5)
Database connection closed
Postgres logs show me the following:
<date> <time> <timezone> [14860] LOG: could not receive data from client: An existing connection was forcibly closed by the remote host.
<date> <time> <timezone> [14860] LOG: could not receive data from client: An existing connection was forcibly closed by the remote host.
My drizzle.config.ts looks like this:
import { defineConfig } from 'drizzle-kit'
import { config } from 'dotenv'
import { resolve } from 'path'

const loadEnv = () => {
config()
config({ path: resolve(process.cwd(), '.env.local'), override: true })
}
loadEnv()
const { DATABASE_URL } = process.env

if (!DATABASE_URL) {
throw new Error('DATABASE_URL is not set in the environment variables')
}
export default defineConfig({
schema: './src/dao/schema.ts',
out: './drizzle',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL!,
},
})
import { defineConfig } from 'drizzle-kit'
import { config } from 'dotenv'
import { resolve } from 'path'

const loadEnv = () => {
config()
config({ path: resolve(process.cwd(), '.env.local'), override: true })
}
loadEnv()
const { DATABASE_URL } = process.env

if (!DATABASE_URL) {
throw new Error('DATABASE_URL is not set in the environment variables')
}
export default defineConfig({
schema: './src/dao/schema.ts',
out: './drizzle',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL!,
},
})
I have verified that the environment variable for the URL is being pulled correctly. The weird thing is, I get the exact same setup working without issues on my macOS machine.
14 replies