© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago
Amur

Ignore foreign key violation on bulk insert

Is there a way to just skip the value, or even better make it null if one of the values from a bulk insert vauses a
foreign key violation
foreign key violation
error
for example i have this code, and the second element as a recipeId that doesn't exist so i would get a
foreign key violation 
foreign key violation 
error
Is there a way to just skip the second element or make recipeId null for the second element (recipeId is a nullable field)
  await db.insert(menuItemTable).values([
    {
      menuId: 1,
      name: "test item 1",
      description: "item.description",
      price: 12, 
      recipeId: 8,
    },
    {
      menuId: 1,
      name: "test item 2",
      description: "item.description",
      price: 12, 
      recipeId: 12, // there is no recipe with id 12
    },
    {
      menuId: 1,
      name: "test item 3",
      description: "item.description",
      price: 12,
      recipeId: 8,
    },
  ]);
  await db.insert(menuItemTable).values([
    {
      menuId: 1,
      name: "test item 1",
      description: "item.description",
      price: 12, 
      recipeId: 8,
    },
    {
      menuId: 1,
      name: "test item 2",
      description: "item.description",
      price: 12, 
      recipeId: 12, // there is no recipe with id 12
    },
    {
      menuId: 1,
      name: "test item 3",
      description: "item.description",
      price: 12,
      recipeId: 8,
    },
  ]);
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Is there a way to set foreign key on a bulk insert?
Drizzle TeamDTDrizzle Team / help
2y ago
ON DUPLICATE KEY UPDATE with bulk insert?
Drizzle TeamDTDrizzle Team / help
3y ago
Foreign Key - On Delete
Drizzle TeamDTDrizzle Team / help
3y ago
foreign key
Drizzle TeamDTDrizzle Team / help
3y ago