My problem
I'm building my first api using Laravel and am getting a multiple primary key defined error while trying to run php artisan migrate I don't understand how I have defined multiple primary keys. Every time I run a migrate I get these errors
.
My Troubleshooting
I thought since autoIncrementing() can only be used for a primary key that maybe that defined it as a primary key, so I altered $table->increments('bus_id')->autoIncrement()->primary(); to $table->increments('bus_id')->autoIncrement(); and $table->increments('bus_id')->autoIncrement();
Every time I had tried to run my migrations, I dropped my database and re-created it and tried to run my migrations again (so it was a new database every time with no corrupt data) but still didn't make a difference.
I checked my Connection.php that was mentioned in the picture of my error code above but didn't see anything pertaining to any primary keys.
My Question
My code is below, can someone help me understand how I'm making double primary keys?
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePurchaseHistoryTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('purchase_history', function (Blueprint $table) {
$table->increments('pur_id', 11);
$table->string('pur_item', 255);
$table->dateTimeTz('pur_date');
$table->string('bus_name', 50);
$table->double('pur_amount', 10, 2);
$table->double('cashback_amount', 10, 2);
$table->integer('bus_id', 11);
$table->foreign('bus_id')->references('bus_id')->on('business');
$table->timestamps();
$table->rememberToken();
$table->engine = 'InnoDB';
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('purchase_history');
}
}
Please note there are similar questions here on stack overflow which I have also tried their solutions without any success After edit I'm still getting this error:
In Connection.php line 664:
SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto colu mn and it must be defined as a key (SQL: create tablepurchase_history(pur_idint unsigned not null auto_incre ment primary key,pur_itemvarchar(255) not null,pur_datedatetime not null,bus_namevarchar(50) not null,pur_amountdouble(10, 2) not null,cashback_amountdouble(10, 2) not null,bus_idint not null auto_increment primary key,created_attimestamp null,updated_attimestamp null,remember_tokenvarchar(100) null) default character set utf8mb4 collate utf8mb4_unicode_ci engine = InnoDB)
After running php artisan migrate:refresh


Try these
incrementsbus_idis and foreign key thenunsignedit before addreferencescategoryhas defined/created beforepurchase_historytable and category tableauto-incrementfield isbus_idFYI: If I draw table the I set
idas a name on the auto-increment field. because no confusion.