Hi there this my code but I receive this error:
SQLSTATE[42000]: Syntax error or access violation: 1068 Multiple primary key defined (SQL: alter table `wishlists` add primary key (`userId`, `productId`))
The code:
public function up()
{
Schema::create('wishlists', function (Blueprint $table) {
$table->id();
// Foreign key for Users table
$table->foreignId('userId');
$table->foreign('userId')->references('id')->on('users')->onDelete('cascade');
// Foreign key for Products table
$table->foreignId('productId');
$table->foreign('productId')->references('id')->on('products')->onDelete('cascade');
$table->primary(['userId', 'productId']);
$table->timestamps();
});
}
thanks
I've been search about it but couldn't find anything
Problem solved!
I just had to remove
$table->id();. because the table is a relevant and don't need ID.