drizzle-team / drizzle-team/drizzle-orm

[BUG]: npx drizzle-kit introspect --> drizzle-kit/bin.cjs:21699 TypeError: Cannot read properties of undefined (reading 'toLowerCase')

Open
#2,426 3 comments 2 reactions 0 assignees View on GitHub
bug bug/cant-reproduce db/postgres drizzle/kit priority
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### What version of `drizzle-orm` are you using?

0.31.0

### What version of `drizzle-kit` are you using?

0.22.1

### Describe the Bug

When using "npx drizzle-kit introspect" the command runs, but does not complete. Throws the following error.

```sh
$ npx drizzle-kit introspect
drizzle-kit: v0.22.1
drizzle-orm: v0.31.0

No config path provided, using default path
Reading config file '...PATH_TO_PROJECT_ROOT/drizzle.config.ts'
Pulling from ['public'] list of schemas

Using 'postgres' driver for database querying
[✓] 18 tables fetched
[⢿] 89 columns fetching
[✓] 9 enums fetched
[⢿] 0 indexes fetching
[⢿] 5 foreign keys fetching

.../node_modules/drizzle-kit/bin.cjs:21699
const onUpdate = fk4.update_rule.toLowerCase();
^

TypeError: Cannot read properties of undefined (reading 'toLowerCase')
at ..PATH_TO_PROJECT_ROOT/node_modules/drizzle-kit/bin.cjs:21699:48
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v22.1.0
```

``` Typescript
// config.drizzle.ts
import { config } from 'dotenv';
import { defineConfig } from 'drizzle-kit';
import { resolve } from 'path';

// Load environment variables from .env.local
// Next JS uses .env.local instead of .env see: https://nextjs.org/docs/basic-features/environment-variables
config({
path: [resolve(__dirname, '.env.local'), resolve(__dirname, '.env')],
});

// Drizzle-Kit Specific Configuration
export default defineConfig({
schema: './src/db/schema.ts',
out: './supabase/migrations',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL!,
},
});
```

---
Tried trouble shooting.
Error replicates with new project using an example schema given in the Supabase/Drizzle docs.

The example schema used:
```typesript
// dasdf
import {
pgTable,
serial,
text,
timestamp,
integer,
varchar,
boolean,
} from 'drizzle-orm/pg-core';

export const usersTable = pgTable('users_table', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
age: integer('age').notNull(),
email: text('email').notNull().unique(),
});

export const postsTable = pgTable('posts_table', {
id: serial('id').primaryKey(),
title: text('title').notNull(),
content: text('content').notNull(),
userId: integer('user_id')
.notNull()
.references(() => usersTable.id, { onDelete: 'cascade' }),
createdAt: timestamp('created_at').notNull().defaultNow(),
updatedAt: timestamp('updated_at')
.notNull()
.$onUpdate(() => new Date()),
});

export type InsertUser = typeof usersTable.$inferInsert;
export type SelectUser = typeof usersTable.$inferSelect;

export type InsertPost = typeof postsTable.$inferInsert;
export type SelectPost = typeof postsTable.$inferSelect;
```

Run the following commands:
```sh
npx drizzle-kit generate
npx drizzle-kit migrate
npx drizzle-kit pull
npx drizzle-kit introspect
```
Getting same error in shell:
```sh
$ npx drizzle-kit introspect
drizzle-kit: v0.22.1
drizzle-orm: v0.31.0

No config path provided, using default path
Reading config file '..PATH_TO_PROJECT_ROOT/drizzle.config.ts'
Pulling from ['public'] list of schemas

Using 'postgres' driver for database querying
[✓] 2 tables fetched
[⣽] 6 columns fetching
[✓] 9 enums fetched
[⣽] 0 indexes fetching
[⣽] 3 foreign keys fetching
..PATH_TO_PROJECT_ROOT/node_modules/drizzle-kit/bin.cjs:21699
const onUpdate = fk4.update_rule.toLowerCase();
^

TypeError: Cannot read properties of undefined (reading 'toLowerCase')
at ..PATH_TO_PROJECT_ROOT/node_modules/drizzle-kit/bin.cjs:21699:48
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v22.1.0

```

### Expected behavior

Would expect it to complete introspection and generate the schema.ts file in the location specified in the config.drizzle.ts file.

### Environment & setup

Using Supabase and Next JS.
Taking database and contents from an existing Django projects.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.