From 2b1f9dcc72ffbac0c27aa09f474cea92c67de045 Mon Sep 17 00:00:00 2001 From: Nathan Long Date: Fri, 14 Jul 2023 10:25:31 -0400 Subject: [PATCH] Show how to modify the cascade of a foreign key (#536) --- lib/ecto/migration.ex | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/ecto/migration.ex b/lib/ecto/migration.ex index 169b4b49..b7baeeb1 100644 --- a/lib/ecto/migration.ex +++ b/lib/ecto/migration.ex @@ -1208,6 +1208,12 @@ defmodule Ecto.Migration do modify :title, :text, null: false, from: {:string, null: true} end + # Modify the :on_delete option of an existing foreign key + alter table("comments") do + modify :post_id, references(:posts, on_delete: :delete_all), + from: references(:posts, on_delete: :nothing) + end + ## Options * `:null` - determines whether the column accepts null values. If this option is