#22656 closed Bug (wontfix)
Adding check for FK that blank=False when null=False
Reported by: | ANUBHAV JOSHI | Owned by: | ANUBHAV JOSHI |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When ForeignKey is not given null=True with blank=True, there are problems at the time of saving.
Adding a validation check enforcing that blank=False when null=False to catch such errors/warnings and displaying appropriate message so that the user is fully aware of the situation.
Change History (7)
comment:1 Changed 7 years ago by
Has patch: | set |
---|---|
Owner: | changed from nobody to ANUBHAV JOSHI |
Status: | new → assigned |
comment:2 follow-up: 6 Changed 7 years ago by
I assume you meant "blank=False when null=False" instead of "null=True with blank=True"?
comment:3 Changed 7 years ago by
I'm not sure this is something we want to add as it will break backwards compatibility. For example, "Leaving a field blank and filling it in in the model's save() method seems to be a pretty common case" -from django-users.
comment:4 follow-up: 5 Changed 7 years ago by
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
Agreed with Tim, that's a use case we want to support.
comment:5 Changed 7 years ago by
Replying to aaugustin:
Agreed with Tim, that's a use case we want to support.
I have added this for ForeignKey
only not for other fields. In others it is fine but in FK it will create database errors
on save()
if any object is not provided.
If null=False then keeping blank=True for ForeignKey
is wrong and will lead to errors in save() as said above. I think that was what I wanted to say and could not explain earlier.
I wanted to improve error reporting so I opened this. Also as said in #13776, what in case of is_valid
??
comment:6 Changed 7 years ago by
Replying to aaugustin:
I assume you meant "blank=False when null=False" instead of "null=True with blank=True"?
I meant the case where null=False and blank=True for ForeignKey
comment:7 Changed 7 years ago by
As noted in #13776, the use case worked in Django 1.0, but broke in 1.2. We should try to fix it rather than just disallow it.
https://github.com/django/django/pull/2686