Opened 6 years ago

Closed 6 years ago

#29904 closed Bug (invalid)

Not Null CharField Doesn't generate DB constraint on Oracle

Reported by: Vackar Afzal Owned by: nobody
Component: Migrations Version: 2.0
Severity: Normal Keywords: Contraints
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Given the following model:

class User(models.Model):
    myField1 = models.CharField(max_length=20)
    myField2 = models.CharField(max_length=20, blank=True)
    myField3 = models.CharField(max_length=20, null=True, blank=True)

I would expect myField1 and field2 to have a db constraint assigned to ensure that they are not null.
However all columns are nullable upon inspection via 3rd party db tool.
Is this by design, or a genuine bug?

Change History (4)

comment:1 by Vackar Afzal, 6 years ago

Summary: Not Null CharField Doesn't generate DB constrain on OracleNot Null CharField Doesn't generate DB constraint on Oracle

comment:2 by Tim Graham, 6 years ago

Resolution: invalid
Status: newclosed
Type: UncategorizedBug

Please read NULL and empty strings.

In the future, please use the resources linked from TicketClosingReasons/UseSupportChannels to ask "is it a bug?" questions.

comment:3 by Vackar Afzal, 6 years ago

Resolution: invalid
Status: closednew

Thanks for the information. After reviewing however I would argue that this behaviour is invalid.
I agree that an empty string and a null value are under most circumstances interchangeable, but this is being conflated with the concept of nullability.
Nullability has nothing to do with the representation of the null, just wether or not the field may be null.
i.e If a column has a not null constraint, it should not accept an empty string or 'Null'
With Django's current behaviour, since declaring a field as not null has no effect, both 'Null' and blank strings may be inserted without issue.
I would argue that this is a broken design. How are raw queries enforced, or additional clients that have no knowledge of the Django's internal checks and conversions?
If Django needs to do internal checks, it should use the value of 'blank' and not 'null' to be consistent with other backends. Oracle supports not null constraints, why not exploit that?

Last edited 6 years ago by Vackar Afzal (previous) (diff)

comment:4 by Tim Graham, 6 years ago

Resolution: invalid
Status: newclosed

I don't know much about the design decision but it dates to the beginning of the OracleBranch in 2006. If you want to revisit that decision, you should make a proposal on the DevelopersMailingList so it'll reach a wider audience. This should include at least a description of the change you're proposing and the backwards compatibility considerations. If you can put together a patch to demonstrate that your idea is feasible and passes Django's test suite, that will no doubt help your proposal. Thanks!

Note: See TracTickets for help on using tickets.
Back to Top