This is a temporary solution for seeding databases with Drizzle ORM (drizzle-seed) when junction tables cause duplicate key violations. It seeds main tables first using seed, then manually seeds junction tables with fetched IDs to ensure uniqueness.
- Replace
schemaanddbimports with your own schema and database connection. - Update
mainTableswith your main entity tables (e.g.,users,products). - Add your junction tables in the seeding section (e.g.,
userProducts). - Run with your preferred runtime (e.g.,
bun run seed.ts).