Answer the question
In order to leave comments, you need to log in
Laravel migration?
tell me how to make a migration so that stock_status_id can have duplicates and when adding, if it is not specified, then substitute the values as an auto-increment?
Schema::create('stock_statuses', function (Blueprint $table) {
$table->unsignedBigInteger('stock_status_id')->autoIncrement();
$table->unsignedBigInteger('language_id');
$table->foreign('language_id')
->references('id')->on('localizations')
->onDelete('cascade');
$table->string('name')->nullable();
$table->timestamps();
});
Answer the question
In order to leave comments, you need to log in
Autoincrement should still be assigned to id as the primary key, and not to stock_status_id, as you have now in the example. The logic of "doubles or autoincrement" needs to be done at the application level, or rather, the model level and the insert event.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question