drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[BUG]: drizzle-kit generate not working without error

Open jofflin opened this issue 11 months ago • 18 comments

Report hasn't been filed before.

  • [x] I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

1.0.0-beta.2-58a4521

What version of drizzle-kit are you using?

1.0.0-beta.2-58a4521

Other packages

No response

Describe the Bug

I updated from beta1 to beta2. After doing some schema changes I wanted to generate the migration files. This told me to run drizzle-kit up, which i did.

Everything's fine 🐶🔥

Then i run generate again and it still told me to run the up command. The meta folder did not get deleted. Maybe a separate bug which was already mentioned on Discord. After deleting the meta folder manually i run generate again and then it fails without any information:

~/Development/nono/nono-monorepo/packages/database  feat/email-marketing ❯ pn db:generate

> @nono/[email protected] db:generate /Users/jofflin/Development/nono/nono-monorepo/packages/database
> drizzle-kit generate

No config path provided, using default 'drizzle.config.ts'
Reading config file '/Users/jofflin/Development/nono/nono-monorepo/packages/database/drizzle.config.ts'
[[email protected]] injecting env (1) from .env.local -- tip: 🔄 add secrets lifecycle management: https://dotenvx.com/ops

 ELIFECYCLE  Command failed with exit code 1.

jofflin avatar Dec 11 '25 09:12 jofflin

https://discord.com/channels/1043890932593987624/1233509562771046430/1448277718746533960 Similar issue here with bunx

jofflin avatar Dec 11 '25 09:12 jofflin

I am also experiencing this issue. That discord link doesn't appear to work @jofflin .

joe3dgroup avatar Dec 11 '25 16:12 joe3dgroup

You can look into their Discord, in the #kit-beta channel

jofflin avatar Dec 12 '25 08:12 jofflin

Experiencing the same issue

tsatsujnr139 avatar Dec 12 '25 17:12 tsatsujnr139

please share original migrations folder, I will create a test case and fix

AlexBlokh avatar Dec 14 '25 23:12 AlexBlokh

Sure, thank you. If I can assist any further, please let me know

migrations.zip

jofflin avatar Dec 15 '25 08:12 jofflin

Some more info on this, as I am getting (probably) the same error. I am using it on a random hobby project so I can share the whole repo if needed. It happens on a fresh install too. I just created a svelte kit app and installed drizzle:

"drizzle-kit": "^1.0.0-beta.3-702eadc",
"drizzle-orm": "^1.0.0-beta.3-702eadc",

Running drizzle-kit generate gives me this:

bunx drizzle-kit generate
No config path provided, using default 'drizzle.config.ts'
Reading config file '/home/zinnavoy/Documents/Hobby/anchorhold/drizzle.config.ts'
 Error  Cannot find module '$lib/server/database/entities/specie.entity'
Require stack:
- /home/zinnavoy/Documents/Hobby/anchorhold/src/lib/server/database/entities/character.entity.ts
- /home/zinnavoy/Documents/Hobby/anchorhold/node_modules/drizzle-kit/bin.cjs

I tried registering the path alias from svelte kit's lib using tsconfig-paths (found this solution on a answeroverflow post):

import { defineConfig } from 'drizzle-kit';
import { register } from 'tsconfig-paths';
import tsConfig from './.svelte-kit/tsconfig.json';

register({
  baseUrl: '.',
  paths: tsConfig.compilerOptions.paths,
});

if (!process.env.DATABASE_URL) throw new Error('DATABASE_URL is not set');

export default defineConfig({
  out: './src/lib/server/database/migrations',
  schema: './src/lib/server/database/entities',

  dialect: 'postgresql',
  casing: 'snake_case',
  dbCredentials: { url: process.env.DATABASE_URL },

  verbose: true,
  strict: true,
});

Didn't help. It just failed silently:

> bunx drizzle-kit generate
No config path provided, using default 'drizzle.config.ts'
Reading config file '/home/zinnavoy/Documents/Hobby/anchorhold/drizzle.config.ts'

The migrations folder was created but there is nothing inside. drizzle-kit up prints Everything's fine 🐶🔥 And drizzle-kit migrate gives and error (I mean, probably because there is no migrations right? But including for info).

> bunx drizzle-kit migrate
No config path provided, using default 'drizzle.config.ts'
Reading config file '/home/zinnavoy/Documents/Hobby/anchorhold/drizzle.config.ts'
Using 'postgres' driver for database querying
[⣷] applying migrations... Error  Failed query: CREATE SCHEMA IF NOT EXISTS "drizzle"
params:

Zinnavoy avatar Dec 21 '25 06:12 Zinnavoy

I also get the same error when i run drizzle-kit generate: drizzle-kit generate

No config path provided, using default 'drizzle.config.ts' Reading config file 'C:\Users\Vishal Raj Kumar\Documents_coading-folder\ainumsworld\drizzle.config.ts'

 ELIFECYCLE  Command failed with exit code 1.

vishalx07 avatar Dec 22 '25 01:12 vishalx07

Should be fixed in drizzle-orm@beta and drizzle-kit@beta

Exact version is: [email protected] and [email protected]

Make sure to up from a previous folder structure

AndriiSherman avatar Dec 22 '25 08:12 AndriiSherman

@AndriiSherman this still seems to be occurring on beta 4 I'm afraid.

GWAnthonyAdams avatar Dec 22 '25 15:12 GWAnthonyAdams

@AndriiSherman having the same issue in v1.0.0-beta.6 as well

coldter avatar Dec 25 '25 12:12 coldter

@coldter @GWAnthonyAdams how can I reproduce it? do you have a migration folder before using drizzle-kit up or maybe after using it?

AndriiSherman avatar Dec 25 '25 13:12 AndriiSherman

@AndriiSherman

So i figured this only happens when we have folder for schema in drizzle.config file and that folder has a source file that reexports table definitions. In my case I have a schema folder with index.ts file that reexports tables which is a common pattern for me. Removing index file or setting "schema": "[folder]/index.ts" works.

Here is the reproduction on drizzle-benchmark repo https://github.com/coldter/drizzle-beta-migration-gen-bug/commit/e9b24577180e22e157209d157418ff952bba4886


FYI

running drizzle-kit generate after drizzle-kit up with correct config also results in an error. In my case I got:

{
  nameExplicit: true,
  columns: [
    {
      value: 'order_id',
      isExpression: false,
      asc: true,
      nullsFirst: false,
      opclass: null
    }
  ],
  isUnique: false,
  where: null,
  with: '',
  method: null,
  concurrently: null,
  name: 'order_id_idx',
  schema: 'public',
  table: 'order_details',
  entityType: 'indexes'
}

drizzle/20230813113328_flat_master_mold/snapshot.json data is malformed

coldter avatar Dec 25 '25 15:12 coldter

still get the same error after updating to v1.0.0-beta.6-4414a19 drizzle-kit generate

No config path provided, using default 'drizzle.config.ts' Reading config file 'C:\Users\Vishal Raj Kumar\Documents_coading-folder\ainumsworld\drizzle.config.ts'

 ELIFECYCLE  Command failed with exit code 1.

vishalx07 avatar Dec 25 '25 15:12 vishalx07

@vishalx07 if you have folder(with index.ts that reexports your table def) for schema in your drizzle.config.ts try to set schema in your drizzle.config.ts to that index.ts file

coldter avatar Dec 25 '25 16:12 coldter

@coldter thanks a lot, i fixed my issue by adding index.ts in drizzle.config.ts.

before:

import { defineConfig } from "drizzle-kit";
import { env } from "@/env";

export default defineConfig({
  schema: "./src/server/db/schema",
  dialect: "postgresql",
  dbCredentials: {
    url: env.DATABASE_URL,
  },
  casing: "snake_case",
  strict: true,
  verbose: true,
});

After:

import { defineConfig } from "drizzle-kit";
import { env } from "@/env";

export default defineConfig({
  schema: "./src/server/db/schema/index.ts",
  dialect: "postgresql",
  dbCredentials: {
    url: env.DATABASE_URL,
  },
  casing: "snake_case",
  strict: true,
  verbose: true,
});

vishalx07 avatar Dec 25 '25 16:12 vishalx07

Oh, that was it then. It fixed for me too.

By the way, is removing the index.ts barrel file and leaving the schema option as schema: "./src/server/db/schema", fine for the drizzle.config? I mean, does it import schemas for every file in that folder? Or do we really need to specify a single file for the schema? I am pretty sure that in the stable version you can point the schema option to a folder and it'll read through all files (so you don't need the barrel export)

Zinnavoy avatar Dec 26 '25 15:12 Zinnavoy

@AndriiSherman seems my issue was completely unrelated, having 2 enums with the same name fails to generate the migration but does not throw an error when attempting to generate the migration

GWAnthonyAdams avatar Dec 29 '25 08:12 GWAnthonyAdams