I'm working on 4 tables and here is the query:
CREATE TABLE "User" (
"UserID" int,
"Username" varchar(20),
"Password" varchar(20),
"Email" varchar(50),
"MonthlyBudget" float(2),
PRIMARY KEY ("UserID")
);
CREATE TABLE "FoodCategory" (
"CategoryID" int,
"CategoryName" varchar(20),
"TotalSpent" float(2),
PRIMARY KEY ("CategoryID")
);
CREATE TABLE "Inventory" (
"InventoryID" int,
"UserID" int,
"ItemID" int,
"MonthlyTotal" float(2),
PRIMARY KEY ("InventoryID"),
CONSTRAINT "FK_Inventory.UserID"
FOREIGN KEY ("UserID")
REFERENCES "User"("UserID")
);
CREATE TABLE "GroceryItem" (
"ItemID" int,
"CategoryID" int,
"FoodName" varchar(50),
"Price" float(2),
"ExpiryDate" date,
"ShopDate" date,
"QtyPurchased" int,
"QtyConsumed" int,
"Expired" bool,
"Picture" varchar(255),
PRIMARY KEY ("ItemID"),
CONSTRAINT "FK_GroceryItem.ItemID"
FOREIGN KEY ("ItemID")
REFERENCES "Inventory"("ItemID")
);
Why do I keep getting this ERROR: there is no unique constraint matching given keys for referenced table "Inventory" ? I'm trying to create 4 tables and they have references to each one. I keep on getting this error. I'm not sure how to fix it. Can someone help?