I am new to laravel when adding a new column to the existing table I am getting the above error:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (
schoolmanagement.#sql-314_2c, CONSTRAINTstudents_parentsid_foreignFOREIGN KEY (parentsid) REFERENCESparent_names(id) ON DELETE CASCADE) (SQL: alter tablestudentsadd constraintstudents_parentsid_foreignforeign key (parentsid) referencesparent_names(id) on delete cascade)
at
public function up(){
Schema::table('students', function (Blueprint $table)
{
$table->unsignedBigInteger('parentsid')->after('id');
$table->foreign('parentsid')->references('id')->on('parent_names')->onDelete('cascade');
});
}
public function down()
{
Schema::table('students', function (Blueprint $table) {
//
});
}
just need to insert a column for the existing table with foreign key