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

[DOCS] Are columns nullable by default? #2207

Closed
TheGlenn88 opened this issue Jul 21, 2023 · 2 comments · Fixed by #2262
Closed

[DOCS] Are columns nullable by default? #2207

TheGlenn88 opened this issue Jul 21, 2023 · 2 comments · Fixed by #2262
Labels

Comments

@TheGlenn88
Copy link

I've been on a wild goose chase this morning because there was a period of time that my migrations have changed behaviour on allow null by default for columns, twice in 6 months, so I have a long period where my columns are NOT NULL, a 6 month period where they became allow NULL, recently moving back to NOT NULL.

$this->table('user_things')
            ->addColumn('user_uuid', 'uuid')
            ->addColumn('is_thing', 'boolean', ['default' => false])
            ->create();

If we take the above code as an example. According to the documentation, the user_uuid column should allow nulls.

My understanding however has been that to allow null you would have to explicitly write
->addColumn('user_uuid', 'uuid', ['null' => true])

There have been some changes to Phinx to change this behaviour recently, it appears it may have changed a few times in the past too.

The docs need updating because it currently reads:

allow NULL values, defaults to false if identity option is set to true, else defaults to true

which is untrue as of 0.13.4

I'm not sure what this should read, because I don't know if it's as simple as.

allow NULL values, defaults to false

Can someone with a more in depth understanding of how Phinx works update the docs to reflect it's current effect of 'default'.

@dereuromark
Copy link
Member

dereuromark commented Jul 21, 2023

Changelogs/ReleaseNotes and the feature flag topic will probably give some insight: https://github.com/cakephp/phinx/releases

@MasterOdin
Copy link
Member

The behavior for null was changed in 0.13.0 which hopefully clarifies behavior:

set column null by default unless identity by @MasterOdin in #1872. Previously columns were created as NOT NULL by default, and to now get that behavior, you will need to explicitly pass 'null' => false in the column options.

Ideally we'd be able to do the simple "always default to false", but need to put in the bit about identity which inverses the default if enabled which is annoying to describe tersely.

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

Successfully merging a pull request may close this issue.

3 participants