1
 public function up()  {          
    Schema::create('orders', function (Blueprint $table) {          
         $table->increments('id');   
         $table->unsignedBigInteger('seller_id');   
         $table->foreign('seller_id')->references('id')->on('sellers')->onDelete('cascade');   
         $table->decimal('total',8,2);  
         $table->decimal('discount',8,2)->default(0);    
         $table->decimal('tax',8,2);   
         $table->boolean('paid')->default(0);          
         $table->timestamps();  
    }); 
}

sellers table

public function up() {  

    Schema::create('sellers', function (Blueprint $table) {
        
        $table->increments('id'); 
        $table->string('CompanyName');  
        $table->string('SellerName');  
        $table->string('email')->unique();  
        $table->string('password');
        $table->bigInteger('contact');
        $table->mediumText('officeAddress');
        $table->string('city');
        $table->string('state');
        $table->rememberToken();
        $table->timestamps();

    });

}

I tried all possible ways to define foreign key but couldn't get success please help me out enter image description here

Ritik Rai
  • 11
  • 3

1 Answers1

3

increments()

The increments method creates an auto-incrementing UNSIGNED INTEGER equivalent column as a primary key:

$table->increments('id');

The id column on the sellers table is defined using $table->increments('id');

The referencing column seller_id in the orders table must have a matching data type.

Solution

Orders migration.




 public function up()  {          
    Schema::create('orders', function (Blueprint $table) {          
         // ...  
         $table->unsignedInteger('seller_id');   
         // ...
          
    }); 
}
steven7mwesigwa
  • 5,701
  • 3
  • 20
  • 34