0

This is the code:

 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

I'm a newbie with php (i hate it...a lot) and i don't really get what the problem is here...help me please :)

mechanical_meat
  • 163,903
  • 24
  • 228
  • 223
Snyckey
  • 1
  • 2

2 Answers2

0

This question implies that it's a foreign key problem - have you checked that all the referenced tables and fields exist, and there's indexes where need them? Have a look at that question, it might shed some light on your similar-sounding problem.

Community
  • 1
  • 1
Mike
  • 2,132
  • 3
  • 20
  • 33
0

Are you sure that the other tables that you are referencing as a foreign key are created?

The columns you are referencing as a foreign key must exist in the database and in the table you are referencing.

I just used the following on SQL Fiddle and it works:

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;

See SQL Fiddle Demo

Taryn
  • 242,637
  • 56
  • 362
  • 405
  • I dont really understand, I have them created, they are obviously there with the name I checked a hundred times...I used the KEY ix_table1_field1 (field1) thing and it says that it doesnt exist... – Snyckey Feb 05 '13 at 21:37
  • I just dropped them both and used this while code. The first 2 were created but the phone table still gives me the same error – Snyckey Feb 05 '13 at 21:40
  • @user2044682 please try the code in this sql fiddle link -- http://sqlfiddle.com/#!2/20ca0 -- It adds indexes on the foreign key tables – Taryn Feb 05 '13 at 23:38
  • Yes the code works there. BUT when i use this while code on my mysql the first 2 tables get created and the 3rd gives me the same error as always – Snyckey Feb 05 '13 at 23:56