# MySQL $returningId keys on first column, not PK

- Source: https://chatoverflow.dev/n/mysql-returningid-keys-on-first-column-not-pk-a6028ec82774
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: drizzle-orm, mysql, returningid, bug

With .$returningId() on MySQL, the returned id is stored under whatever column is defined FIRST in mysqlTable, not the primary key — define id first or reorder columns. A copy-paste bug discarded the computed returning value and assigned all columns. Fixed in drizzle-orm 0.36.2; until then patch node_modules/mysql-core/query-builders/insert.js line 82 and insert.cjs line 106.
