Add ShopDB schema: create tables and foreign keys#170
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because the current database schema for the Orders table does not meet the required contract and is causing test failures. Specifically, in task.sql, Orders is defined with OrderID and ProductID columns instead of the required CustomerID INT NULL and Date DATE, and there is no foreign key from Orders(CustomerID) to Customers(ID) ON DELETE SET NULL, which the task explicitly requires and the tests rely on. This is a critical blocker because the test script expects an Orders.CustomerID column and fails with Unknown column 'CustomerID' in 'field list'.
To fix this, update the Orders table definition so it has exactly: ID INT AUTO_INCREMENT PRIMARY KEY, CustomerID INT NULL, and Date DATE, and add FOREIGN KEY (CustomerID) REFERENCES Customers(ID) ON DELETE SET NULL; remove the incorrect OrderID and ProductID columns from Orders. After that, ensure OrderItems still has OrderID INT NULL and ProductID INT NULL with the existing foreign keys FOREIGN KEY (OrderID) REFERENCES Orders(ID) ON DELETE SET NULL and FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE SET NULL. Besides this issue, your Products, Customers, and OrderItems tables are generally aligned with the requirements, so once you correct Orders and rerun the tests, the solution should be in good shape. Keep going — this is a solid start, and fixing the Orders schema will complete the task requirements.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| CREATE TABLE Orders( | ||
| ID INT AUTO_INCREMENT PRIMARY KEY, | ||
| OrderID INT NULL, | ||
| ProductID INT NULL |
There was a problem hiding this comment.
The Orders table does not match requirements. Requirement: Orders must have columns ID, CustomerID, and Date. Currently it has OrderID and ProductID columns instead of CustomerID and Date and no foreign key to Customers is defined. Update the table to include CustomerID INT NULL and Date DATE and add a foreign key: FOREIGN KEY (CustomerID) REFERENCES Customers(ID) ON DELETE SET NULL.
| CREATE TABLE OrderItems ( | ||
| ID INT AUTO_INCREMENT PRIMARY KEY, | ||
| OrderID INT NULL, | ||
| ProductID INT NULL, | ||
| FOREIGN KEY (OrderID) REFERENCES Orders(ID) ON DELETE SET NULL, | ||
| FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE SET NULL |
There was a problem hiding this comment.
OrderItems correctly references Orders(ID) and Products(ID), but since Orders lacks CustomerID/Date the schema is incomplete per requirements. After fixing Orders, ensure OrderItems keeps OrderID and ProductID as INT and the foreign keys with ON DELETE SET NULL (this line is fine).
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am approving your solution because your task.sql script correctly creates the ShopDB database and all four required tables (Products, Customers, Orders, OrderItems) with the exact column names and allowed data types. The primary keys are defined with AUTO_INCREMENT, and all required foreign keys are present with the correct ON DELETE SET NULL behavior, so referential integrity and deletion rules match the specification. The table creation order ensures that referenced tables (Customers, Products, Orders) exist before their foreign keys are declared, so this should run cleanly in MySQL without errors.
There are no critical or blocking issues preventing the schema from functioning or from passing the described tests. As minor, optional improvements, you could consider marking columns like Products.Name or Customers.Email as NOT NULL and adding indexes on foreign key columns for better performance, but these are not required by the task. Overall, your implementation meets the requirements and is ready to be used with the provided tests.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| # Write your SQL code for the database creation here. Good luck! | ||
| CREATE DATABASE ShopDB; | ||
| USE ShopDB; | ||
|
|
||
| CREATE TABLE Products ( | ||
| ID INT AUTO_INCREMENT PRIMARY KEY, |
There was a problem hiding this comment.
The script creates the required schema and tables and uses allowed data types and AUTO_INCREMENT primary keys. However, MySQL may require the referenced tables to exist before adding foreign keys; since Customers and Products are defined before Orders and OrderItems respectively, the foreign keys look fine. One minor issue: some VARCHAR lengths for LastName/Email/Address differ from typical allowed sizes in the description but still use allowed types (VARCHAR(50) or VARCHAR(100)), which is acceptable. No syntax errors found.
No description provided.