cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2.3, Cannot able to edit or delete the Foreign Key Column

Magento 2.3, Cannot able to edit or delete the Foreign Key Column

I have a student table.. with fields entity id(primary key), and student id..

now i have created a field in the customer_entity table as student id..

i have applied foreign key to the student id in customer table using this:

 

->addForeignKey(
$installer->getFkName('customer_entity',
'student_id',
'student_table',
'student_id'),
'customer_entity',
'student_id',
$installer->getTable('student_table'),
'student_id'
,
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE);

there is no error.. but now if i am trying to edit or delete the student id in student table it is giving me error..

 

SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`magento`.`customer_entity`, CONSTRAINT `CUSTOMER_ENTITY_STUDENT_ID_STUDENT_TABLE_STUDENT_ID` FOREIGN KEY (`student_id`) REFERENCES `student_table` (`student_id`) ON DELETE CASCADE), query was: UPDATE `student_table` SET `student_id` = ? WHERE (entity_id='1')

 

can anyone help?