lemmon
153
7
Laravel

onDelete cascade not deleting references

Posted 6 days ago by lemmon

WampServer Version 3.1.9 64bit MySQL 5.7.26

when I delete a project the activity does not get removed from the database as well.

Please help thank you.

public function up()
{
    Schema::create('projects', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->unsignedInteger('owner_id');
        $table->string('title');
        $table->text('description');
        $table->text('notes')->nullable();
        $table->timestamps();


        $table->foreign('owner_id')->references('id')->on('users')->onDelete('cascade');
    });
}
public function up()
{
    Schema::create('activities', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->unsignedInteger('project_id');
        $table->unsignedInteger('user_id');
        $table->nullableMorphs('subject');
        $table->text('changes')->nullable();
        $table->string('description');
        $table->timestamps();

        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

        $table->foreign('project_id')->references('id')->on('projects')->onDelete('cascade');
    });
}

Please sign in or create an account to participate in this conversation.