Jump to content

[SOLVED] Help with foreign key error 1005


landysaccount

Recommended Posts

Hello.

 

I'm trying to test something I read in a book but, I'm getting an  error and can't figure out where is the mistake.

 

I get error 105/1005 cant' create table survey_responses.

 

Here's my sql script:

create table survey_question(
    quest_id  int(3) unsigned not null auto_increment,
    question  varchar(80) not null,
    primary key( quest_id )
)
engine=innodb;

/*    Survey answers    */
create table survey_anwers(
    ans_id int(3) unsigned not null auto_increment,
    quest_id int(3) unsigned not null,
    ans_text varchar(40) not null,
    primary key( ans_id ),
    foreign key( quest_id ) references survey_question( quest_id )
)
engine=innodb;
/*    Survey responses    */
create table survey_responses(
    resp_id int(10) unsigned not null auto_increment,
    quest_id int(3) unsigned not null,
    ans_id int(3) unsigned not null,
    primary key ( resp_id ),
    foreign key( quest_id ) references survey_question( quest_id ),
    foreign key( ans_id ) references survey_answers( ans_id )
)
engine=innodb;

 

Both foreign keys are of the same type and size... What am I doing wrong?

 

Thanks in advanced for your help.

Link to comment
https://forums.phpfreaks.com/topic/179741-solved-help-with-foreign-key-error-1005/
Share on other sites

I read this post:

 

http://www.phpfreaks.com/forums/index.php/topic,274744.0.html

 

but, still can't find help. Even read the http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html

and followed the suggestions but, still can't get it right.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.