@4ever_bad Have you checked the following discussion? It seems a similar issue like you.
https://stackoverflow.com/questions/20512572/duplicate-key-on-write-or-update
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi. I'm tried to migrate my php files and an error has appear with table "topic".
Error:
SQLSTATE[HY000]: General error: 1005 Can't create table portal.topic (errno: 121 "Duplicate key on write or update") (SQL: alter table topic add constraint category_id foreign key (category_id) references categories (id) on delete restrict on update restrict)
Migration:
public function up()
{
Schema::create($this->tableName, function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->bigIncrements('id');
$table->string('name');
$table->text('description');
$table->unsignedBigInteger('category_id');
$table->index(["category_id"], 'category_id');
$table->foreign('category_id', 'category_id')
->references('id')->on('categories')
->onDelete('restrict')
->onUpdate('restrict');
});
}
I created migrations using MySQL Workbench and all tables and relations was really fine there.
What can solve my issue?
@4ever_bad Have you checked the following discussion? It seems a similar issue like you.
https://stackoverflow.com/questions/20512572/duplicate-key-on-write-or-update
Please or to participate in this conversation.