Skip to content
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

Open
SyedTauhidUllahShah opened this issue Jan 12, 2024 · 3 comments
Open

Violate foreign key constraints. #11

SyedTauhidUllahShah opened this issue Jan 12, 2024 · 3 comments

Comments

@SyedTauhidUllahShah
Copy link

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.

@adnanzaki19
Copy link

adnanzaki19 commented Jan 12, 2024

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?
For testing purposes, I just trimmed down the data in the csv files for these^

@SyedTauhidUllahShah SyedTauhidUllahShah changed the title Foriegn Key conflict Violate foreign key constraints. Jan 12, 2024
DeliKhan added a commit to DeliKhan/eng-intern-assessment-data that referenced this issue Jan 13, 2024
@shirinyamani
Copy link

I had the same problem! they seems to not match with one another!

DeliKhan added a commit to DeliKhan/eng-intern-assessment-data that referenced this issue Jan 15, 2024
@samyarsworld
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants