#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 by , 10 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
follow-up: 6 comment:2 by , 10 years ago
I assume you meant "blank=False when null=False" instead of "null=True with blank=True"?
comment:3 by , 10 years ago
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.
follow-up: 5 comment:4 by , 10 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
Agreed with Tim, that's a use case we want to support.
comment:5 by , 10 years ago
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 by , 10 years ago
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 by , 10 years ago
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