-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Violate foreign key constraints. #11
Comments
I also had this issue with Cart_Items and Reviews:(. Like they said^, the 'child' tables seem to be referencing ids that don't exist in the 'parent' tables? |
I had the same problem! they seems to not match with one another! |
For this particular assignment, adding more data would merely help with testing and sanity checks. For instance checking averages would only make sense if you have more than one data point. Adding the data in would be as straightforward as copy-pasting Excel rows. However, a more precise way of doing this would be removing the referenced missing items either using code or by using Excel/Workbench UI (for small datasets like this). |
Shopify#11. Made a copy to avoid potential data loss.
For the "CREATE TABLE Order_Items (
order_item_id INT PRIMARY KEY,
order_id INT,
product_id INT,
quantity INT,
unit_price DECIMAL(10, 2),
FOREIGN KEY (order_id) REFERENCES Orders(order_id),
FOREIGN KEY (product_id) REFERENCES Products(product_id)
);"
The product table have only 16 id's, which means that when inserting the data into the Order_Items table beyond 16 entries, it will cause an issue.
This is because the FOREIGN KEY constraint in the Order_Items table ensures that every product_id referenced in Order_Items must already exist in the Products table. If the Products table only has entries up to product_id 16, any INSERT statement in Order_Items that references a product_id higher than 16 will violate the foreign key constraint and result in an error.
The text was updated successfully, but these errors were encountered: