<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateOrderProductTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('order_product', function (Blueprint $table) {
$table->bigIncrements('order_id');
$table->foreign('order_id')->references('id')->on('orders');
$table->bigIncrements('product_id');
$table->foreign('product_id')->references('id')->on('products');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('order_product');
}
}
I expected to create a pivot table, but when I run the "php artisan migrate" it give me this:
SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key
(SQL: create table order_product
(order_id
bigint unsigned not null auto_increment primary key, product_id
bigint unsigned not null auto_increment primary key) default character set utf8mb4 collate
'utf8mb4_unicode_ci')
What is wrong with my code? :(