Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: $returningId returns an empty array unless primaryKey() is put directly on the column #4302

Open
1 task done
ramoneres opened this issue Mar 21, 2025 · 0 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@ramoneres
Copy link

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.40.1

What version of drizzle-kit are you using?

0.30.5

Other packages

No response

Describe the Bug

DB: mysql
orm: 0.40.1
kit: 0.30.5

$returningId() should return the inserted row's ID, but it returns an empty array unless primaryKey() is added to the column directly, instead of in the callback.

The following works fine.

export const table = mysqlTable("table", {
	id: serial().notNull().primaryKey()
},
(table) => [
	primaryKey({ columns: [table.id], name: "id"}),
]);

This does not work


export const table = mysqlTable("table", {
	id: serial().notNull()
},
(table) => [
	primaryKey({ columns: [table.id], name: "id"}),
]);

Not a huge problem, just add primaryKey to the column right? Well, not if you constantly pull the schema from the DB. The generated schema will not add primaryKey to the column directly, only in the callback function, so you have to manually add it to all columns every time you pull the schema.

@ramoneres ramoneres added the bug Something isn't working label Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant