Vaclav,

With your approach, fields are correctly created with / without null 
constraints based on the value of the 'null' parameter.
However subsequent changes are not being picked up by the migrations 
framework. i.e. if I change null=True to null=False, constraint is not 
dropped. The same is true going from False to True, the constraint is not 
added. Did you have to monkey patch the migrations module to get it to 
work, or do you have some other approach?

Many Thanks,
Vackar

On Thursday, 8 November 2018 13:10:30 UTC, Václav Řehák wrote:
>
>
> While it is probably not possible to change how Django treats this, many 
> newcomers find it super confusing. To make developer experience in our 
> Oracle-based project better, we started using the following workaround for 
> fields which are required to be not null and not empty string:
>
> class NonEmptyCharField(models.CharField):
>     """
>     CharField preventing empty string and null
>
>     It workarounds two problems:
>
>     - CharField has a default value '' which allows silent save of model 
> without an error even
>       if we forget to set mandatory fields. This is solved by setting the 
> default to None causing
>      db error on not null constraint.
>
>     - The above is not sufficient for Oracle as the db backend has 
> hardcoded null=True regardless
>       of what we set. This is changed by empty_strings_allowed=False.
>     """
>     empty_strings_allowed = False
>
>     def __init__(self, *args, **kwargs):
>         kwargs.setdefault('default', None)
>         super().__init__(*args, **kwargs)
>
> Dne čtvrtek 8. listopadu 2018 13:43:25 UTC+1 Florian Apolloner napsal(a):
>>
>> Oracle treats NULL and empty varchar2 the same; so null=True/False is 
>> simply not possible on Oracle for CharField. I am not sure what you are 
>> proposing here…
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/fb28b18e-70c2-4fe8-b88d-98edd18e5f2b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to