skip to Main Content

Laravel – How can I avoid a duplicate entry error with a factory referencing two tables?

I have a table migration with a unique condition on item_id and user_id fields: Schema::create('item_user', function (Blueprint $table) { $table->id(); $table->foreignId('item_id')->references('id')->on('items')->onUpdate('RESTRICT')->onDelete('CASCADE'); $table->foreignId('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('CASCADE'); $table->boolean('active')->default(false); $table->date('expires_at')->nullable(); $table->timestamps(); $table->unique(['item_id', 'active', 'user_id'], 'item_item_id_active_user_id_index'); }); I got error duplicate entry on item_id and user_id fields…

VIEW QUESTION
Back To Top
Search