1
create table enquiry (
    eqid integer not null auto_increment primary key,
    question varchar(500),
    cusID integer(100),
    tpid integer(100),
    staffid integer(100)
 );

alter table enquiry add foreign key(tpid) references tourpackage (tpid) ON DELETE CASCADE ON UPDATE CASCADE;

alter table enquiry add foreign key(staffid) references staff (staffid) ON DELETE CASCADE ON UPDATE CASCADE;

alter table enquiry add foreign key(cusID) references customer (cusID) ON DELETE CASCADE ON UPDATE CASCADE;

insert into enquiry
    values (0, "What is the minimum travel group size?",0,0,0);

insert into enquiry
    values (0, "Can we return at a later date?",0,0,0);

insert into enquiry
    values (0, "I would like to use my KrisFlyer miles points to redeem an air ticket. Is it possible?",0,0,0);

I have problem inserting my enquiry values in. Error state that cannot add or update child row.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
Cherlyn
  • 19
  • 4
  • Show that actual error message please – MatBailie Feb 04 '18 at 12:17
  • @MatBailie Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails (`mydatabase`.`enquiry`, CONSTRAINT `enquiry_ibfk_1` FOREIGN KEY (`tpid`) REFERENCES `tourpackage` (`tpid`) ON DELETE CASCADE ON UPDATE CASCADE) – Cherlyn Feb 04 '18 at 12:18

1 Answers1

0

Your inserts should probably look like this:

insert into enquiry (question)
    values ('What is the minimum travel group size?');

You should not be inserting into the auto-incremented primary key. Let the database do the work for you there.

I am guessing that the "0" values for the other columns are intended to mean "no reference". If so, let the database just insert NULLs. Otherwise, you need to be sure that each reference table has a "0" value.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786