drizzle-orm: [BUG]: drizzle-kit push:mysql throws error with only connectionString

What version of drizzle-orm are you using?

0.26.1

What version of drizzle-kit are you using?

0.18.1

Describe the Bug

When I try to migrate (push) my schema to my DB it throws an error Error: Either connectionStringorhost, port, etc. params be provided in config file.

drizzle.config.ts

import type { Config } from "drizzle-kit";

export default {
  schema: "./db/schema/*",
  out: "./db/drizzle",
  connectionString: process.env["DATABASE_URL"],
} satisfies Config;
/db/index.ts

import { drizzle } from "drizzle-orm/planetscale-serverless";
import { connect } from "@planetscale/database";

// create the connection
const connection = connect({
  url: process.env["DATABASE_URL"],
});

export const db = drizzle(connection);

However I specified the connectionString… Am I doing something wrong here?

Expected behavior

It should push to db if I declared connectionString

Environment & setup

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 18

Most upvoted comments

Hi all,

If you’re using NextJS, don’t forget to change the path in dotenv.config({ path: 'your-env-path' }). It took me a while before I realised I had the variable stored in .env.local so I had to change my drizzle.config.ts to:

import type { Config } from 'drizzle-kit';
import * as dotenv from 'dotenv';

dotenv.config({
  path: '.env.local',
});

export default {
  schema: './src/lib/clients/planetscale/schema.ts',
  out: './src/lib/clients/planetscale/migrations',
  driver: 'mysql2',
  dbCredentials: {
    connectionString: process.env.DATABASE_URL as string,
  },
} satisfies Config;

Additionally; you could create a ‘normal’ .env file and put your credentials there and dotenv would find them automatically as that’s it’s default path.

if you do not want to use dotenv package in Nextjs then use @next/env:

import { cwd } from 'node:process';
import type { Config } from 'drizzle-kit';
import { loadEnvConfig } from '@next/env';

loadEnvConfig(cwd());

export default {
  schema: './src/db/schema.ts',
  driver: 'mysql2',
  dbCredentials: {
    connectionString: process.env.DATABASE_URL as string,
  },
} satisfies Config;

Ok, I just realized this was due to me/NextJS…

Since I was just running drizzle-kit push:mysql it didn’t load env variable… When replacing that with the actual string it works 👍

However, does anyone know how this could be fixed to work with .env normally?

I had this issue as well until I realized the same thing, the env variable was not being loaded.

Assuming your drizzle.config.ts file is located in the root directory like mine is, the way I was able to get the environment variable to load was by using the dotenv library. I discovered this by looking at this example from the docs, where they are also using dotenv to load the variable while having their drizzle.config.ts file in the root directory.

Hope this helps!

Ok, I just realized this was due to me/NextJS…

Since I was just running drizzle-kit push:mysql it didn’t load env variable… When replacing that with the actual string it works 👍


However, does anyone know how this could be fixed to work with .env normally?

someone found a solution for this on SvelteKit?

Anyone having difficultly connecting with local mysql?

Like my string is: mysql://username:password@localhost:3306/masterdb

I can easily connect the same in terminal and tableplus but here it gives me this error:

code: 'ERR_INVALID_URL'

This came after I solved the error mentioned in this issue.

Hi, i still have an error : “No config path provided, using default 'drizzle.config.ts” despite i followed all thread’s recommandations …

drizzle.config.ts

import * as dotenv from "dotenv";
import type { Config } from "drizzle-kit";

dotenv.config({ path: ".env" });

export default {
  schema: "./schema.ts",
  out: "./migrations",
  driver: "pg",
  dbCredentials: {
    connectionString: process.env.DATABASE_URL as string,
  },
} satisfies Config;

db.ts

import * as dotenv from "dotenv";
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as schema from "./schema";

dotenv.config({ path: ".env" });

const client = postgres(process.env.DATABASE_URL as string, { max: 1 });
export const db = drizzle(client, { schema });

all my files are in root directory folder and i’m using supabase as DB

Thanks for your help

In case anyone else runs into this issue. I got the same No config path provided, using default 'drizzle.config.ts' error by using drizzle-kit generate:pg when I should have been using drizzle-kit generate:sqlite.

ok, got same problem and just realize connectionString only exist in pg driver, i use mysql2 driver so i use uri

export default {
  schema: "./src/db/schema.js",
  out: './drizzle',
  driver: 'mysql2',
  dbCredentials: {
    uri: process.env.DB_URL
  }
}

I’m using Next version 13.4.19 and drizzle-kit 0.19.13 and is unable to access the studio. Here is my config file :

import type { Config } from "drizzle-kit";
import * as dotenv from "dotenv";
dotenv.config({ path: ".env" });

export default {
  driver: "pg",
  schema: "./src/lib/db/schema.ts",
  dbCredentials: {
    connectionString: process.env.DB_URL!,
  },
} satisfies Config;

While running npx drizzle-kit studio , it tells me that no config path is provided and reading config file from /drizzle.config.ts. The studio gets up and running but when I visit the URL, I am encountered with Problem Loading Page. Not sure what happened wrong because all the packages are installed properly.

Hi, Did you solve it? I’ve tried all methods of this thread and none worked.

No config path provided, using default path Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string

My problem persist if I still have values in the .env file. When removing the values, I can see the .env.local are being used. Still not ideal for me…

I’m using Next version 13.4.19 and drizzle-kit 0.19.13 and is unable to access the studio.

Here is my config file :

import type { Config } from "drizzle-kit";
import * as dotenv from "dotenv";
dotenv.config({ path: ".env" });

export default {
  driver: "pg",
  schema: "./src/lib/db/schema.ts",
  dbCredentials: {
    connectionString: process.env.DB_URL!,
  },
} satisfies Config;

While running npx drizzle-kit studio , it tells me that no config path is provided and reading config file from /drizzle.config.ts.

The studio gets up and running but when I visit the URL, I am encountered with Problem Loading Page.

Not sure what happened wrong because all the packages are installed properly.

Hi, Did you solve it? I’ve tried all methods of this thread and none worked.

No config path provided, using default path Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string

Accessing envs depends on your environment. In my case running anything from within my app (SvelteKit) get access to env via the special helper $env in SvelteKit. When I run migrations outside of my app via a local node script, it’s process.env.SOME_VAR. So you need to check in which env (app-wise but also if local or remote/production) your script is really running and then, google how to get the env vars there. So, it’s often more complicated than expected, mind to close that issue since it’s not one with drizzle?