Laravel delete foreign key Constraint Using Migration

Today, We want to share with you Laravel delete foreign key Constraint Using Migration.In this post we will show you laravel delete foreign key constraint, hear for laravel migration remove foreign key constraint we will give you demo and example for implement.In this post, we will learn about Laravel – How to remove foreign key constraint using migration? with an example.

Laravel delete foreign key Constraint Using Migration

There are the Following The simple About laravel disable foreign key constraint Full Information With Example and source code.

Read Also:  Toggle Switch Button in VueJs Example

As I will cover this Post with live Working example to develop laravel migration drop foreign key, so the laravel delete row with foreign key is used for this example is following below.

Full example of Laravel drop foreign key constraint Using Migration

Step 1: Check If a Column Exists in Laravel Migration File

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProductsTable extends Migration
{
    public function up()
    {
        Schema::table('products', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id');
            $table->string('slug');
            $table->string('description');
            $table->string('short_description');
            $table->string('meta_data');
            $table->string('variations');
            $table->string('default_attributes');
            $table->string('src');
            $table->string('images');
            $table->string('tags');
            $table->string('categories');
            $table->string('shipping_required');
            $table->string('tax_status');
            $table->string('stock_status');
            $table->string('catalog_visibility');
            $table->string('price');
            $table->string('status');
            $table->string('sku')->unique();
            $table->string('attributes');
            $table->rememberToken();
            $table->timestamps();
            $table->foreign('user_id')->references('id')->on('movies')->onDelete('cascade');
			
        });
    }

    public function down()
    {
	    Schema::table('products', function(Blueprint $table) {
            $table->dropForeign('user_id');
            
        });
    }
}

Step 2: run artisan command for create a database

php artisan migrate

Step 3: run the migration using Terminal :For delete:-

php artisan migrate:rollback

Web Programming Tutorials Example with Demo

Read :

Read Also:  Remove undefined value from jquery array

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel drop foreign Key in Migration.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  laravel checking if record exists
  2. Read Also:  vue.js Get Current DateTime Example
  3. Read Also:  Simple AutoComplete AngularJS Example
  4. Read Also:  Task Scheduling with Cron Job using Laravel 5/6/7
  5. Read Also:  Laravel 6 return view jQuery ajax request example
  6. Read Also:  Bootstrap 4 Search Box With Dropdown List
  7. Read Also:  get product with Rakuten Marketing API using PHP
  8. Read Also:  open new tab in reactjs Example Tutorial
  9. Read Also:  Laravel get last Eloquent print query
  10. Read Also:  Polymorphism in PHP Object-oriented programming Examples
CLOSEX