MySQL ERROR 1452 : Foreign Key Constraint

217
June 11, 2017, at 8:24 PM

I have a parent table. One column of the table is referenced as a foreign key to another table. The parent table has correct data in the referenced column. When I am trying to insert to the child table I am facing foreign key constraint error. The value for the referenced column is present in the parent table.

Parent table structure :

CREATE TABLE linked_in_profile_data_values (
  LINKED_IN_PROFILE_DATA_VALUES_ID varchar(45) NOT NULL,
  LINKED_IN_PROFILE_DATA_ID varchar(45) NOT NULL,
  IS_CURRENT tinyint(4) DEFAULT NULL,
  SUMMARY varchar(45) DEFAULT NULL,
  TITLE varchar(45) DEFAULT NULL,
  user_id int(10) NOT NULL,
  LINKED_IN_PROFILE_DATA_VALUES_PK varchar(45) NOT NULL,
  PRIMARY KEY (LINKED_IN_PROFILE_DATA_VALUES_ID,LINKED_IN_PROFILE_DATA_ID,user_id),
  UNIQUE KEY LINKED_IN_PROFILE_DATA_VALUES_PK_UNIQUE (LINKED_IN_PROFILE_DATA_VALUES_PK),
  KEY FX2_LINKED_IN_PROFILE_DATA_ID_idx (LINKED_IN_PROFILE_DATA_ID),
  CONSTRAINT FX2_LINKED_IN_PROFILE_DATA_ID FOREIGN KEY (LINKED_IN_PROFILE_DATA_ID) REFERENCES linked_in_profile_data (LINKED_IN_PROFILE_DATA_ID) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Child Table Structure :

CREATE TABLE linked_in_profile_data_company (
  LINKED_IN_PROFILE_DATA_COMPANY_ID varchar(45) NOT NULL,
  LINKED_IN_PROFILE_DATA_VALUES_PK varchar(45) DEFAULT NULL,
  LINKED_IN_PROFILE_DATA_NAME varchar(45) DEFAULT NULL,
  PRIMARY KEY (LINKED_IN_PROFILE_DATA_COMPANY_ID),
  KEY FK_VALUES_PK_idx (LINKED_IN_PROFILE_DATA_VALUES_PK)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Insert query :

insert into linked_in_profile_data_company 
values(1111,'XYZ','ed1ee991-4d14-11e7-b5d8-5d15c209e35f');

Note : "ed1ee991-4d14-11e7-b5d8-5d15c209e35f" value is present in the parent table.

READ ALSO
Storing information in MYSQL DB with PHP OOP

Storing information in MYSQL DB with PHP OOP

I have the below code all indications show it is working I get the "Sucess" message and the echos within the storeData() function are showing the correct informationHOWEVER the data is not being store in the Mysql database, nothing is happening

170
How can i update a mysql db column that only depends on a timestamp?

How can i update a mysql db column that only depends on a timestamp?

Lets say I have a Table tbl_Room with a column taken (boolean) and a Customer wants to rent this room for a short period

136
How can I search/filter 2 MySQL tables using PHP

How can I search/filter 2 MySQL tables using PHP

I have a question on how to search 2 MySQL database tables using PHPI was able to display and search one table as shown below

193
Opening MySQL.Data source from Github source

Opening MySQL.Data source from Github source

I am trying to build the source for thenet connector c# in Visual Studio 2017

231