Skip to content

Loading…

DDC-102: Is a field nullable by default or not? #1609

Closed
doctrinebot opened this Issue · 6 comments

2 participants

@doctrinebot

Jira issue originally created by user @beberlei:

JPA specifies a field to be nullable by default, however $classMetadata->isNullable('fieldName') on a field which has no 'nullable' key returns false.

This leads to strange errors, SchemaTool createSQL assumes like JPA that fields are nullable by default. However updateSchemaSql uses isNullable which assumes the opposite.

This can lead to situations there is always a ALTER TABLE NOT NULL is suggested by the SchemaTool, although this is already set, only because the 'nullable' key is not set in the metadata of an entity.

@doctrinebot

Comment created by @beberlei:

Attached is a patch.

@doctrinebot

Comment created by romanb:

As far as I can remember normal columns (@Column) should be not nullable (nullable = false) by default and join columns the other way around. I know this is different from the spec but its much more in-line with common usage. Nullable columns are pretty rare in practice and indeed usually discouraged. For foreign keys on the other hand it is obvious that when the association is optional the foreign key must be nullable. And since all associations are optional by default, join columns should be nullable by default.

@doctrinebot

Comment created by @beberlei:

In this case I will fix createSql() assuming notnull = false in SchemaTool, which is a bugfix nevertheless :-)

@doctrinebot

Comment created by @beberlei:

Fixed, Assumption is now that nullable = false

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.0-ALPHA3 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.