title: Foreign Key Constraint error for delete data form table
body: <p>i am doing a project on ONLINE EXAMINATION which is copied from my senior but while execute i got some error. attach my code here and the error msg.</p>
  
  <p><strong>table #:</strong> </p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `question` (
    `testid` bigint(20) NOT NULL DEFAULT '0',
    `qnid` int(11) NOT NULL DEFAULT '0',
    `question` varchar(500) DEFAULT NULL,
    `optiona` varchar(100) DEFAULT NULL,
    `optionb` varchar(100) DEFAULT NULL,
    `optionc` varchar(100) DEFAULT NULL,
    `optiond` varchar(100) DEFAULT NULL,
    `correctanswer` enum('optiona','optionb','optionc','optiond') DEFAULT NULL,
    `marks` int(11) DEFAULT NULL,
    PRIMARY KEY (`testid`,`qnid`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  </code></pre>
  
  <p>--</p>
  
  <h2>-- Dumping data for table <code>question</code></h2>
  
  <pre><code>INSERT INTO `question` (`testid`, `qnid`, `question`, `optiona`, `optionb`, `optionc`,     `optiond`, `correctanswer`, `marks`) VALUES
  (1, 1, 'why use photoshop', 'image retouching', 'image making', 'image destroying',     'color coreection', 'optiona', 1),
  (2, 1, 'java is', 'fish fry', 'software language', 'programing language', 'web maker',     'optionc', 1),
  (2, 2, 'what is vaja', 'bengali', 'kokl', 'khsd', 'kojsgf', 'optiona', 1);
  </code></pre>
  
  <p>Table ###</p>
  
  <p>--</p>
  
  <h2>-- Table structure for table <code>student</code></h2>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `student` (
   `stdid` bigint(20) NOT NULL,
   `stdname` varchar(40) DEFAULT NULL,
   `stdpassword` varchar(40) DEFAULT NULL,
   `emailid` varchar(40) DEFAULT NULL,
   `contactno` varchar(20) DEFAULT NULL,
   `address` varchar(40) DEFAULT NULL,
   `city` varchar(40) DEFAULT NULL,
   `pincode` varchar(20) DEFAULT NULL,
   PRIMARY KEY (`stdid`),
   UNIQUE KEY `stdname` (`stdname`),
   UNIQUE KEY `emailid` (`emailid`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  </code></pre>
  
  <p>--</p>
  
  <h2>-- Table structure for table <code>studentquestion</code></h2>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `studentquestion` (
    `stdid` bigint(20) NOT NULL DEFAULT '0',
    `testid` bigint(20) NOT NULL DEFAULT '0',
    `qnid` int(11) NOT NULL DEFAULT '0',
    `answered` enum('answered','unanswered','review') DEFAULT NULL,
    `stdanswer` enum('optiona','optionb','optionc','optiond') DEFAULT NULL,
    PRIMARY KEY (`stdid`,`testid`,`qnid`),
    KEY `testid` (`testid`,`qnid`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  </code></pre>
  
  <hr>
  
  <pre><code>--
  -- Constraints for table `question`
  --
  ALTER TABLE `question`
    ADD CONSTRAINT `question_ibfk_1` FOREIGN KEY (`testid`) REFERENCES `test` (`testid`);
  
  --
  -- Constraints for table `studentquestion`
  --
  ALTER TABLE `studentquestion`
    ADD CONSTRAINT `studentquestion_ibfk_1` FOREIGN KEY (`stdid`) REFERENCES `student`     (`stdid`),
    ADD CONSTRAINT `studentquestion_ibfk_2` FOREIGN KEY (`testid`, `qnid`) REFERENCES     `question` (`testid`, `qnid`);
  </code></pre>
  
  <hr>
  
  <p><strong>ERROR MESSAGE</strong></p>
  
  <p><strong><em>Cannot delete or update a parent row: a foreign key constraint fails (<code>oes</code>.<code>studentquestion</code>, CONSTRAINT <code>studentquestion_ibfk_2</code> FOREIGN KEY (<code>testid</code>, <code>qnid</code>) REFERENCES <code>question</code> (<code>testid</code>, <code>qnid</code>))</em></strong>  </p>