Friday, March 31, 2017

onDelete('cascade') not deleting data on pivot table

I have the following migration:

 public function up()
    {
        Schema::create('youtube_topics_to_subscriptions', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->integer('topic_id')->unsigned()->index()->references('id')->on('youtube_topics')->onDelete('cascade');
            $table->integer('youtube_subscription_id')->unsigned()->index()->references('id')->on('youtube_subscriptions')->onDelete('cascade');
        });
    }

My undersatnding is that when using onDelete('cascade'), if I delete a subscription, then all associated YoutubeTopicsToSubscriptions will be delete.

When I run App\YoutubeSubscription::truncate(); all the subscriptions are deleted correctly from youtube_subscriptions table but no data is deleted from youtube_topics_to_subscriptions. what am I doing wrong?



via code511788465541441

Advertisement