broke
Constraint error on struct delete while using delete_all option
Hello, I’m getting the following error while running a unit test that deletes an “artist” entity that has “tag” associations (the desired behavior is for the associations to be deleted when the parent is deleted).
** (Ecto.ConstraintError) constraint error when attempting to delete struct:
* artist_tags_artist_id_fkey (foreign_key_constraint)
If you would like to stop this constraint violation from raising an
exception and instead add it as an error to your changeset, please
call `foreign_key_constraint/3` on your changeset with the constraint
`:name` as an option.
The changeset has not defined any constraint.
code: assert {:ok, %Artist{}} = Artists.delete_artist(artist)
stacktrace:
(ecto 3.2.5) lib/ecto/repo/schema.ex:689: anonymous fn/4 in Ecto.Repo.Schema.constraints_to_errors/3
(elixir 1.10.0) lib/enum.ex:1396: Enum."-map/2-lists^map/1-0-"/2
(ecto 3.2.5) lib/ecto/repo/schema.ex:674: Ecto.Repo.Schema.constraints_to_errors/3
(ecto 3.2.5) lib/ecto/repo/schema.ex:451: anonymous fn/10 in Ecto.Repo.Schema.do_delete/4
test/narktar/artists_test.exs:75: (test)
This is the migration used to create the join-table “artist_tags” where I use on_delete: :delete_all
def change do
create table(:artist_tags) do
add :artist_id, references(:artists, on_delete: :delete_all), null: false
add :tag_id, references(:tags, on_delete: :delete_all), null: false
timestamps()
end
create unique_index(:artist_tags, [:artist_id, :tag_id])
end
I verified there is CASCADE ON DELETE on the foreign key constraint in the Postgres database, and have no problems deleting artists (and their associated tags) manually with queries against Postgres.
I feel Iike I might be missing something simple and any help would be appreciated. I can also post any more details regarding the parent schemas if that would be useful.
First Post!
dimitarvp
Last Post!
Nicd
Popular in Questions
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Hi everyone,
I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Other popular topics
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
I would like to know what is the best IDE for elixir development?
New
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something…
Haskell reminds me of Java, and e...
New
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









