Brandan
Brandan

Reputation: 11

How to have multiple ProductIDs in an order MySQL

I'm pretty new to all of this. I have database set up for an online store with the following tables: Customer,Product,Order,Order_Details and Sales. What I'm having trouble with is the Order_details table. For example if a person orders more than one product I can't insert more than one productID. Sorry if I explained this weirdly, any help is appreciated!

https://i.sstatic.net/SY1xa.jpg

Upvotes: 1

Views: 82

Answers (2)

Omari Victor Omosa
Omari Victor Omosa

Reputation: 2879

That is because you have set the productID as a unique index which should not be the case.

Check indexes and see if the productID is a unique index. If it is i would suggest you delete the unique index property for productID

Check indexes and see if the productID is a unique index. If it is i would suggest you delete the unique index property for productID

You may as-well try to have another column for order_number. i.e. generate a unique number for each order but dont set order_number column as a unique column

FOR INSTANCE A cart of five ordered product but with same order_number so that you may group the result as one single cart

Upvotes: 0

Stuart
Stuart

Reputation: 6795

You have the orderID set as a primary key in the order_details table. Remove primary key from that field. Introduce a id column to the order_details table with primary key set.

Upvotes: 1

Related Questions