Directus: Ask for value when changing nullable to not-nullable

Created on 30 Sep 2020  路  3Comments  路  Source: directus/directus

  1. Create some collection
  2. Create and save some field (string is ok)
  3. Edit that same field, try to make it required
  4. Verify that the following error occurs:
{"errors":[{"message":"alter table `collection_a` modify `foo` varchar(255) not null - ER_INVALID_USE_OF_NULL: Invalid use of NULL value","extensions":{"code":"INTERNAL_SERVER_ERROR"}}]}

Modal remains open and if you close it, required is checked. But if you refresh the page, then required appears unchecked (as if the change has been applied at app-memory level, but not in the database)

Expected behaviour: the user should be able to make a previously created unrequired field required by updating it

EDIT: It seems this happens when you already have created items. I tried to delete the previously created items, then the app allowed me to make that field required. IMHO it should allow to change it anyway.

API App New Feature

Most helpful comment

That makes sense @lluishi93, but Directus mirrors the actual database, and therefore uses allow_null for this. The problem being that the database itself enforces this... and won't allow NULLs in a column with allow_null set to false.

Perhaps we can warn the admin when trying to set this that we'll have to batch update all existing records with the field default value (which may be an empty string). Would that work @rijkvanzanten ?

All 3 comments

Expected behaviour: the user should be able to make a previously created unrequired field required by updating it

We should figure out what we expect to happen here. You can't require a column to have a value if you already have rows without a value. Otherwise, your value requirement doesn't pass 馃

@rijkvanzanten based on other CMSs like Contentful, what happens in this situation is that, once you open the items after the field has been changed to requiere, the form automatically detects the missing field and doesn't let the user save it until the new field is filled. If that is something that Directus should allow or not, depends mostly on you, but I think a lot of user would appreciate this behaviour.

That makes sense @lluishi93, but Directus mirrors the actual database, and therefore uses allow_null for this. The problem being that the database itself enforces this... and won't allow NULLs in a column with allow_null set to false.

Perhaps we can warn the admin when trying to set this that we'll have to batch update all existing records with the field default value (which may be an empty string). Would that work @rijkvanzanten ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

asitemade4u picture asitemade4u  路  3Comments

benhaynes picture benhaynes  路  4Comments

forcemagic picture forcemagic  路  4Comments

Varulv1997 picture Varulv1997  路  4Comments

SharkWipf picture SharkWipf  路  3Comments