drizzle-team / drizzle-team/drizzle-orm

`drizzle-kit generate` does not recognize tables defined with `mysqlSchema().table()` — shows "0 tables"

Open
#5,391 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

# `drizzle-kit generate` does not recognize tables defined with `mysqlSchema().table()` — shows "0 tables"

## Description

When defining tables using `mysqlSchema("schema_name").table("table_name", { ... })`, **drizzle-orm** correctly generates schema-qualified queries at runtime (e.g., `` `schema_name`.`table_name` ``). However, **drizzle-kit generate** completely ignores these tables — it reports "0 tables" and produces no migration SQL.

This means there is currently **no way to use `mysqlSchema()` for cross-database queries AND generate migrations** with drizzle-kit.

## Versions

- `drizzle-orm`: `0.45.1`
- `drizzle-kit`: `0.31.8`
- Database: MySQL 8.x
- Runtime: Bun 1.x / Node.js 22.x

## Steps to Reproduce

**1. Define a table using `mysqlSchema().table()`:**

```ts
// src/lib/server/database/schema_name/table_name.ts
import { sql } from "drizzle-orm";
import { datetime, index, int, mysqlSchema, primaryKey, text, varchar } from "drizzle-orm/mysql-core";

export const schema = mysqlSchema("schema_name");

export default schema.table("table_name", {
...
}, (table) => [
...
]);
```

**2. Configure `drizzle.config.ts`:**

```ts
import { defineConfig } from "drizzle-kit";

export default defineConfig({
out: "./migrate/schema_name",
schema: "./src/lib/server/database/schema_name/*",
dialect: "mysql",
dbCredentials: {
url: "mysql://user:password@host:3306",
},
verbose: true,
strict: true,
});
```

**3. Run `drizzle-kit generate`:**

```
$ drizzle-kit generate
No config path provided, using default 'drizzle.config.ts'
Reading config file '/path/to/project/drizzle.config.ts'
Using 'mysql' driver for database querying
0 tables
0 enums
0 schemas
...
No schema changes, nothing to migrate 😴
```

## Expected Behavior

`drizzle-kit generate` should detect the `table_name` table and produce a migration SQL file with a `CREATE TABLE` statement, respecting the `mysqlSchema("schema_name")` qualifier.

## Actual Behavior

`drizzle-kit generate` reports **0 tables** and produces no migration output. The table is completely invisible to drizzle-kit.

## Workaround Verification

If the same table is defined using `mysqlTable()` instead of `mysqlSchema().table()`:

```ts
import { mysqlTable } from "drizzle-orm/mysql-core";

export default mysqlTable("table_name", {
// ... same columns ...
});
```

Then `drizzle-kit generate` works correctly and produces the expected `CREATE TABLE` SQL. However, this loses schema qualification at runtime — queries target `table_name` instead of `` `schema_name`.`table_name` ``, which breaks cross-database JOIN scenarios on the same MySQL server.

## Additional Context

- `mysqlDatabase()` is also affected, as `mysqlSchema` is simply an alias for `mysqlDatabase` in the source code (`const mysqlSchema = mysqlDatabase;` in `drizzle-orm/mysql-core/schema.js`). Both produce the same result: tables are invisible to drizzle-kit.
- This creates a significant gap: **`mysqlSchema()` is the only API to achieve cross-database JOINs in drizzle-orm**, but it is incompatible with drizzle-kit's migration generation. Users are forced to either:
1. Use `mysqlTable()` and lose cross-database query capability, or
2. Use `mysqlSchema()` and manually write migration SQL.

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.