i am trying to run command php artisan migrate:rollback and it throw me the error cannot update or delete a parent row foreign key constraint fails
there is now issue when i run command php artisan migrate it successfully migrate my all tables but when i run rollback command it throw me the error the error is on my purpose_of_visits migration
public function up()
{
Schema::create('purpose_of_visits', function (Blueprint $table) {
$table->increments('id');
$table->string('purpose', 100);
$table->string('description', 197);
$table->integer('speciality_id')->unsigned()->nullable();
$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->useCurrent();
$table->softDeletes();
$table->integer('created_by')->unsigned()->nullable();
$table->integer('updated_by')->unsigned()->nullable();
$table->foreign('speciality_id')->references('id')->on('specialities')->onDelete('cascade');
$table->foreign('created_by')->references('id')->on('users')->onDelete('cascade');
$table->foreign('updated_by')->references('id')->on('users')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('purpose_of_visits');
}
and my specialities migration:
public function up()
{
Schema::create('specialities', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 50);
$table->string('description',250)->nullable();
$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->useCurrent();
$table->softDeletes();
$table->integer('created_by')->unsigned()->nullable();
$table->integer('updated_by')->unsigned()->nullable();
$table->foreign('created_by')->references('id')->on('users')->onDelete('cascade');
$table->foreign('updated_by')->references('id')->on('users')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('specialities');
}
i cant figure out where is the issue even i am using onDelete('cascade') your help will be highly appreciated!