1

私はerrorno:150MySQLを取得しています。3 番目のテーブルを作成しようとしているときに、Can't create tableと表示されます。以下は完全なクエリです。

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

フィールドの不一致は発生していますか? 私は今立ち往生しています。

4

1 に答える 1

0

外部キー定義の引用に関連しているようです。

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.`),
  /* Remove the backquotes surrounding user(user_id) and product(product_no.) */
  foreign key (`user_id`) references user (user_id),
  /* Inside the parens, `product_no.` should be quoted because of the period */
  foreign key (`product_no.`) references product (`product_no.`)
);

s.nproduct_no.. _ それらは許可されており、引用すると機能しますが、引用が必要になるため、それらを使用することはあまり一般的ではありません。product_noそれ以外の場合は、.なしで名前が付けられた列を引用する必要はありません.

于 2012-05-16T16:56:16.963 に答える