Skip to content

[BUG]: Drizzle not pulling foreign key names using introspect command in ts + mysql #4415

Open
@karanXsportzzbook

Description

@karanXsportzzbook

Report hasn't been filed before.

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

What version of drizzle-orm are you using?

0.41.0

What version of drizzle-kit are you using?

0.30.6

Other packages

No response

Describe the Bug

Drizzle not pulling foreign key names using introspect command. It only pulls self referencing foreign key names.

export const categories = mysqlTable("categories", { id: bigint({ mode: "number", unsigned: true }).autoincrement().notNull(), tournamentId: bigint("tournament_id", { mode: "number", unsigned: true }).notNull().references(() => tournaments.id, { onDelete: "cascade" } ), name: varchar({ length: 255 }).notNull(), eventType: varchar("event_type", { length: 255 }), genderId: bigint("gender_id", { mode: "number", unsigned: true }).references(() => genders.id), gameId: bigint("game_id", { mode: "number", unsigned: true }).notNull().references(() => games.id), parentId: bigint("parent_id", { mode: "number", unsigned: true }), createdAt: timestamp("created_at", { mode: 'string' }), updatedAt: timestamp("updated_at", { mode: 'string' }), }, (table) => [ foreignKey({ columns: [table.parentId], foreignColumns: [table.id], name: "categories_parent_id_foreign" }), primaryKey({ columns: [table.id], name: "categories_id"}), ]);

In the above code foreign key names of tournamentId, genderId, etc are not fetched.

If I continue to run migrations it drops the actual foreign key names in the database and makes its own generated foreign key name which are exceeding the length limit of constraints in mysql

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions