I am getting errorno:150 with MySQL. While i am trying to create the third table it shows Can’t create table. Following is the complete query.
CREATE DATABASE `test`;
USE `test`;
-- --------------------------------------------------------
--
-- Table structure for table `product`
--
CREATE TABLE IF NOT EXISTS `product` (
`product_no.` int(10) NOT NULL AUTO_INCREMENT COMMENT 'This number represent a unique product',
`name` varchar(50) NOT NULL ,
`price` decimal(5,2) NOT NULL COMMENT 'Price should have a fomat like 25.90',
`max_Rating` int(10) NOT NULL COMMENT 'Maximum available rating for each product (n)',
PRIMARY KEY (`product_no.`)
);
-- --------------------------------------------------------
--
-- Table structure for table `user`
--
CREATE TABLE IF NOT EXISTS `user` (
`user_id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`password` varchar(20) NOT NULL,
PRIMARY KEY (`user_id`)
);
-- --------------------------------------------------------
--
-- Table structure for table `rating`
--
CREATE TABLE IF NOT EXISTS `rating` (
`s.n.` int(10) NOT NULL AUTO_INCREMENT,
`product_no.` int(10) NOT NULL,
`user_id` int(10) DEFAULT NULL,
`given_rating` int(10) DEFAULT NULL,
PRIMARY KEY (`s.n.`),
foreign key (`user_id`) references `user(user_id)`,
foreign key (`product_no.`) references `product(product_no.)`
);
Is there any field mismatch happening? I am stuck now.
It looks to be related to the quoting in your foreign key definitions.
I would just note that you won’t often encounter tables named with special characters in them like
s.norproduct_no.. Although they are permitted and work when quoted, it is somewhat uncommon to use them owing to the quoting need they introduce. It would not otherwise be necessary to quote a column namedproduct_nowithout the..