Relational DB Linking Question

PROJECT DETAILS:

Nodejs

LocalHost

MySQL 8

Hey guys,

Quick question about DB Relationships & inserting data into a Referenced DB.

CASE:

DB 1: Product

DB 2: Product Variants (product_id (ref to db 1) >> id)

I am currently using Shopify’s API to grab in both “Parent” product details as well as the “Variant” details to store certain needed parameters of each into my two DB’s as listed above.

Being there will be 100 variants with different “id” in this case all with the same parent “product_id” of 7514679771358, I am trying to fill DB 2 (Product Variants) but get an ERROR for Duplicate Entry Value for 7514679771358.

In the Product_Variants DB - The product_id is set as the Primary Key.

I’ve done a decent amount of research on this and not sure if I need to have some sort of Trigger (not sure how to do this) or what.

Any thoughts / help with this would be awesome as I’m sure others have similar questions that are new to the DB’s and Relations.

Cheers!![Screen Shot 2022-01-18 at 10.05.32 AM|690x415]

(upload://7MSSNKtPRrsyJqMbhC1FMr2fHtA.jpeg)

You’ll see here it inserts one variant, then from the Google Dev tools, the next id (is different for next product variation) but it throws an ERROR because the product_id is the same as the other variation.

In the variant table, id should be set as the unique key, not product_id.

Wow thanks for the quick response Ben!

That did it!

Your the best!

Cheers