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

Default value gets set to 'NULL' when Allow NULL value is changed to true #7522

Closed
3 tasks done
dstoyanoff opened this issue Aug 20, 2021 · 3 comments
Closed
3 tasks done
Assignees

Comments

@dstoyanoff
Copy link
Contributor

Preflight Checklist

Describe the Bug

When a field's Allow NULL value setting is updated from false to true, the column's default value gets set to stringified 'NULL'

To Reproduce

  • Create a new collection
  • create 2 fields
    • field1 - Allow NULL value = true
    • field2 - Allow NULL value = false
  • inspect the database - everything is ok.
  • update field2 to have Allow NULL value = true
  • inspect the database - field2's default value got updated to NULL::character varying

What version of Directus are you using?

v9.0.0-rc.90

What version of Node.js are you using?

v16.5.0

What database are you using?

Postgres 12

What browser are you using?

Edge

What operating system are you using?

macOS

How are you deploying Directus?

Docker

@rijkvanzanten
Copy link
Member

I think this might be a quirk in Postgres actually!

Before:

CleanShot 2021-08-20 at 10 20 09@2x

SQL:

ALTER TABLE articles
	ALTER COLUMN title SET NOT NULL,
	ALTER COLUMN title SET DEFAULT NULL;

After:

CleanShot 2021-08-20 at 10 22 34@2x

@rijkvanzanten
Copy link
Member

It still seems to behave as expected though:

When inserting directly in SQL, omitting the value for title:

ERROR: null value in column "title" of relation "articles" violates not-null constraint

In Directus:

CleanShot 2021-08-20 at 10 26 43@2x

@rijkvanzanten
Copy link
Member

I think this is just a confusing quirk in Postgres on how it displays a default value NULL for string type columns that aren't nullable. No idea why it does that tho!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants