1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] FOREIGN KEY constraint may cause cycles or multiple cascade paths [duplicate]

Discussão em 'Outras Linguagens' iniciado por Stack, Novembro 6, 2024 às 12:52.

  1. Stack

    Stack Membro Participativo

    I'm not sure I'm understanding why I'm encountering this issue and wondering if someone can clear it up for me. Everything I seem to find online is referencing asp.net code but I'm in php/laravel.

    This is my schema for a database table:

    Schema::create('maintenance.work_orders', function (Blueprint $table) {
    $table->id();
    ...
    $table->foreignUuid('assigned_user_id')->nullable()->index()->constrained('dbo.users')->nullOnDelete();
    $table->foreignUuid('created_user_id')->nullable()->index()->constrained('dbo.users')->nullOnDelete();
    $table->foreignUuid('updated_user_id')->nullable()->index()->constrained('dbo.users')->nullOnDelete();
    ...
    });


    When I try to run this schema on the database I get the following error:


    SQLSTATE[42000]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Introducing FOREIGN KEY constraint 'maintenance_work_orders_created_user_id_foreign' on table 'work_orders' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. (Connection: sqlsrv, SQL: alter table "maintenance"."work_orders" add constraint "maintenance_work_orders_created_user_id_foreign" foreign key ("created_user_id") references "dbo"."users" ("id") on delete set null)

    Is it not possible to have multiple ON DELETE SET NULL referencing the same table/column in SQL Server?

    Continue reading...

Compartilhe esta Página