drizzle-team / drizzle-team/drizzle-orm
[BUG]: generated migration with multicolumn foreign keys is wrong
- 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.32.0
### What version of `drizzle-kit` are you using?
0.23.0
### Describe the Bug
The next schema generates migration where both `userId` and `equipmentId` are linked with `users.id`:
```ts
import { sqliteTable, text, integer, foreignKey, } from 'drizzle-orm/sqlite-core'
export const userEquipment = sqliteTable('userEquipment', {
userId:
text('userId'),
equipmentId:
text('equipmentId')
}, (table) => ({
reference: foreignKey({
columns: [table.userId, table.equipmentId],
foreignColumns: [users.id, equipment.id]
})
}))
```
The migration output:
```sql
CREATE TABLE `userEquipment` (
`userId` text,
`equipmentId` text
FOREIGN KEY (`userId`,`equipmentId`) REFERENCES `users`(`id`,`id`) ON UPDATE no action ON DELETE no action
);
```
### Expected behavior
`equipmentId` linked with `equipment.id`, not with `users.id` or throwing an error in case it's impossible.
### Environment & setup
Reproduction: https://stackblitz.com/edit/drizzle-kit-foreign-key-bug?file=schema.js
Contributor guide
Assessment
This issue has not been assessed yet.