1

I am trying to link both these tables with a foreign key. But I keep getting error message "ERROR 1452: Cannot add or update a child row: a foreign key constraint fails " the foreign key is pwalk_id to walk_id

Walk Table
walk_id INT(11) PK NN AI
walk_title NN walk_dur INT(11)
walk_spoint VARCHAR(20)
walk_fpoint VARCHAR(20)
walk_desc TEXT NN

Programme Table
prog_id INT(11) PK NN
pwalk_id INT(11) NN
prog_date DATE NN
prog_stime VARCHAR (9) NN
prog_max INT(11) 

Edit:

CREATE TABLE `Walk` (
  `walk_id` int(11) NOT NULL AUTO_INCREMENT,
  `walk_title` varchar(15) NOT NULL,
  `walk_dur` int(11) NOT NULL,
  `walk_spoint` varchar(20) NOT NULL,
  `walk_fpoint` varchar(20) NOT NULL,
  `walk_desc` text NOT NULL,
  PRIMARY KEY (`walk_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


CREATE TABLE `Programme` (
  `prog_id` int(11) NOT NULL,
  `pwalk_id` int(11) NOT NULL,
  `prog_date` date NOT NULL,
  `prog_stime` varchar(9) NOT NULL,
  `prog_max` int(11) NOT NULL,
  PRIMARY KEY (`prog_id`),
  KEY `Progwalk_idx` (`pwalk_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  • 1
    Can you put the output from show create table <table>; For both tables please.... – Rodrigo Gonzalez Jul 29 '14 at 21:53
  • Rodrigo, I am pretty new to this and not sure how you do that – CmosTech NLondon Jul 29 '14 at 21:58
  • Well, you can use mysql command to connect to DB, or whatever you use to manage it and execute the SQL query I asked – Rodrigo Gonzalez Jul 29 '14 at 21:59
  • Thanks everyone for your help. Just worked out what the issue was, I had left data in the programme table, DOH!!! – CmosTech NLondon Jul 29 '14 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.