0

这是代码:

 CREATE TABLE phone
(
ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
Name varchar(15) not null,
Stock VARCHAR(15) NOT NULL,
FK_manufacturerid INT NOT NULL, 
INDEX (FK_manufacturerid), 
FOREIGN KEY(FK_manufacturerid) REFERENCES manufacturer (manufacturerid)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
FK_osid INT NOT NULL, 
INDEX (FK_osid), 
FOREIGN KEY(FK_osid) REFERENCES os (osid)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
Camera varchar(15) not null,
Handset varchar(15) not null,
Screen varchar(15) not null,  
Connectivity varchar(15) not null,
BatteryLife varchar(15) not null,
Memory varchar(15) not null,
Messaging varchar(15) not null,
SoundFormat varchar(15) not null,
Price int(5) not null,
Flag varchar(3) not null

)ENGINE=InnoDB

我是 php 的新手(我讨厌它......很多),我真的不明白这里的问题是什么......请帮助我:)

4

2 回答 2

0

这个问题暗示这是一个外键问题——您是否检查过所有引用的表和字段是否存在,并且在需要它们的地方有索引?看看那个问题,它可能会对你听起来相似的问题有所启发。

于 2013-02-05T21:16:42.923 回答
0

您确定创建了作为外键引用的其他表吗?

您作为外键引用的列必须存在于数据库和您引用的表中。

我刚刚在 SQL Fiddle 上使用了以下内容,它可以工作:

create table manufacturer
(
  manufacturerid INT NOT NULL AUTO_INCREMENT PRIMARY KEY
) ;

create table os
(
  osid INT NOT NULL AUTO_INCREMENT PRIMARY KEY
) ;

CREATE TABLE phone
(
  ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  Name varchar(15) not null,
  Stock VARCHAR(15) NOT NULL,
  FK_manufacturerid INT NOT NULL, 
  FK_osid INT NOT NULL, 
  Camera varchar(15) not null,
  Handset varchar(15) not null,
  Screen varchar(15) not null,  
  Connectivity varchar(15) not null,
  BatteryLife varchar(15) not null,
  Memory varchar(15) not null,
  Messaging varchar(15) not null,
  SoundFormat varchar(15) not null,
  Price int(5) not null,
  Flag varchar(3) not null,
  INDEX (FK_manufacturerid), 
  FOREIGN KEY(FK_manufacturerid) REFERENCES manufacturer (manufacturerid)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  INDEX (FK_osid), 
  FOREIGN KEY(FK_osid) REFERENCES os (osid)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION

)ENGINE=InnoDB;

请参阅SQL Fiddle 演示

于 2013-02-05T21:16:56.120 回答