I am trying to add the auto-incrementing id to the existing table with its existing primary key
here is my code
initial migration for the table code
public function up()
{
Schema::create('books', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->string('ISBN')->index();
$table->string('name')->index();
$table->string('publisher');
$table->string('level_levelName')->index();
$table->string('provider_providerName')->index();
$table->string('category_categoryName')->index();
$table->text('description');
$table->timestamps();
$table->primary('ISBN');
$table->foreign('provider_providerName')->references('providerName')->on('providers')->onDelete('cascade')->onUpdate('cascade');
$table->foreign('level_levelName')->references('levelName')->on('levels')->onDelete('cascade')->onUpdate('cascade');
$table->foreign('category_categoryName')->references('categoryName')->on('categories')->onDelete('cascade')->onUpdate('cascade');
});
}
add auto incrementint id to existing table code
public function up()
{
Schema::table('books', function (Blueprint $table) {
$table->bigIncrements('id');
});
}
what I am trying to do is add an auto-incrementing id to this existing table but it is giving me this error
SQLSTATE[42000]: Syntax error or access violation: 1068 Multiple primary keys defined (SQL: alter table
`books` add `id` bigint unsigned not null auto_increment primary key)
Please can somebody help me? I don't want to remove table's primary key, I just want to add another auto-incrementing id which is not a primary key but it can be unique key