title: Adding Foreign key but getting constraint violation error
body: <p>I have four tables:</p>
  
  <pre><code>1)Country:Two columns
    a) country_id
    b) country_name
  
  2)State: Three columns
    a) state_id
    b) state_name
    c) country_id(foreign key)
  
   3)City: Three Columns
     a) city_id
     b) city_name
     c) state_id(foreign key)
  
   4) Doctor: 20 Columns
     a) doc_id (primary key)
     b) doc_name
     c) email,gender age and so on 
  </code></pre>
  
  <p>I have populated these tables with dara.</p>
  
  <p>I am adding three new columns: country_id, state_id and city_id in doctor table as a foreign key.</p>
  
  <p>When I insert the country_id, state_id and city_id as a foreign key in that table I got this error </p>
  
  <pre><code>1452 - Cannot add or update a child row: a foreign key constraint fails (`medical_network`.`#sql-4174_45`, CONSTRAINT `#sql-4174_45_ibfk_1` FOREIGN KEY (`country_id`) REFERENCES `country` (`country_id`) ON DELETE CASCADE ON UPDATE CASCADE)
  </code></pre>
  
  <p>I know this is a basic error, but can't find the mistake.</p>
  
  <p>Doctor Table:</p>
  
  <pre><code>CREATE TABLE `doctor` (
   `doc_id` int(9) NOT NULL AUTO_INCREMENT,
   `doc_fname` varchar(15) NOT NULL,
   `doc_lname` varchar(15) NOT NULL,
   `doc_province` varchar(20) NOT NULL,
   `doc_city` varchar(25) NOT NULL,
   `doc_gender` varchar(10) NOT NULL,
   `doc_fathername` varchar(32) NOT NULL,
   `doc_age` varchar(20) NOT NULL,
   `doc_cnic` varchar(16) NOT NULL,
   `doc_medclgname` varchar(100) NOT NULL,
   `doc_specilization` varchar(100) NOT NULL,
   `doc_phoneno` varchar(20) NOT NULL,
   `doc_officeno` varchar(20) NOT NULL,
   `doc_email` varchar(25) NOT NULL,
   `doc_gradyear` int(10) NOT NULL,
   `doc_licenseno` varchar(30) NOT NULL,
   `doc_hosp` varchar(200) NOT NULL,
   `doc_pass` varchar(35) NOT NULL,
   `doc_address` varchar(100) NOT NULL,
   `doc_country` varchar(100) NOT NULL,
   `doc_img` varchar(200) NOT NULL,
   `totime` time NOT NULL,
   `fromtime` time NOT NULL,
   `todate` date NOT NULL,
   `fromdate` date NOT NULL,
   `country_id` int(20) NOT NULL,
   PRIMARY KEY (`doc_id`),
   KEY `country_id` (`country_id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=latin
  </code></pre>
  
  <p>Country Table:</p>
  
  <pre><code>CREATE TABLE `country` (
   `country_id` int(20) NOT NULL AUTO_INCREMENT,
   `country_name` varchar(200) NOT NULL,
   PRIMARY KEY (`country_id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=252 DEFAULT CHARSET=latin1
  </code></pre>
  
  <p>State Table Query:</p>
  
  <pre><code>CREATE TABLE `state` (
   `state_id` int(20) NOT NULL AUTO_INCREMENT,
   `state_name` varchar(200) NOT NULL,
   `country_id` int(20) NOT NULL,
   PRIMARY KEY (`state_id`),
   KEY `country_id` (`country_id`),
   CONSTRAINT `state_ibfk_1` FOREIGN KEY (`country_id`) REFERENCES `country` (`country_id`) ON DELETE CASCADE ON UPDATE CASCADE
  ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1
  </code></pre>
  
  <p>City Table:</p>
  
  <pre><code>CREATE TABLE `city` (
   `city_id` int(20) NOT NULL AUTO_INCREMENT,
   `city_name` varchar(200) NOT NULL,
   `state_id` int(20) NOT NULL,
   PRIMARY KEY (`city_id`),
   KEY `state_id` (`state_id`),
   CONSTRAINT `city_ibfk_1` FOREIGN KEY (`state_id`) REFERENCES `state` (`state_id`) ON DELETE CASCADE ON UPDATE CASCADE
  ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1
  </code></pre>