jackjoe / mailgun_logger

Simple Mailgun log persistence in Phoenix/Elixir
MIT License
74 stars 10 forks source link

Unable to delete Accounts #18

Closed m3techitopsadmin closed 2 years ago

m3techitopsadmin commented 2 years ago

02:42:14.783 [info] DELETE /accounts/8 02:42:14.801 [info] Sent 500 in 18ms 02:42:14.802 [error] #PID<0.3618.0> running MailgunLoggerWeb.Endpoint (connection #PID<0.3547.0>, stream id 21) terminated Server: :5050 (http) Request: POST /accounts/8 (exit) an exception was raised: (Ecto.ConstraintError) constraint error when attempting to delete struct:

* events_account_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.

Getting this error when trying to delete accounts

jeroenbourgois commented 2 years ago

@m3techitopsadmin thanks. It's because there are still events for that account and the proper cascade is not set. However I cannot reproduce this on my side...

I updated the migration none the less, but it might be better if you set the CASCADE option on your database yourself, so that when you delete an account any referencing events are deleted too.

m3techitopsadmin commented 2 years ago

Hi,

Can you provide the mysql script to set this? not to good with MySQL

jeroenbourgois commented 2 years ago

You can look here for examples: https://www.mysqltutorial.org/mysql-on-delete-cascade/