Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with M2O and NOT Allowing NULL #9089

Closed
3 tasks done
benhaynes opened this issue Oct 23, 2021 · 2 comments · Fixed by #11597
Closed
3 tasks done

Error with M2O and NOT Allowing NULL #9089

benhaynes opened this issue Oct 23, 2021 · 2 comments · Fixed by #11597

Comments

@benhaynes
Copy link
Sponsor Member

Preflight Checklist

Describe the Bug

I get a foreign key constraint error when trying to create/edit a M2O field with Nullable disabled (unchecked).

Screen Shot 2021-10-22 at 8 39 31 PM

To Reproduce

  1. Create M2O field
  2. Turn "All NULL Value" Off
  3. Hit Save
  4. See error

Errors Shown

See above.

What version of Directus are you using?

RC.99

What version of Node.js are you using?

7.20.3

What database are you using?

MySQL 5.7.26

What browser are you using?

Chrome

What operating system are you using?

MacOS

How are you deploying Directus?

locally

@Oreilles
Copy link
Contributor

This is expected: the onDelete action is SET NULL- Which means when deleting the referenced item, the database would try to set this column to NUL,L which would break this constraint - so MySQL prevent you from doing this.

( Interestingly, PostgreSQL doesn't complain about it until we actually try to delete the referenced item ).

We could disable the onDelete option and set it to CASCADE automatically when a user makes a relational field non nullable like in your case, but it might not be expected to some users and lead to mistakes. Ultimately it's probably better to leave it as is...

@benhaynes
Copy link
Sponsor Member Author

Ah, that makes sense but it was not obvious to me at all. I'd be fine disabling one of the two, or throwing a notification when both are set... at least explaining to users that they can't do this (before they save and get this technical error).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants