Question

When allowing database fields of a Django model to be NULL using null=True, is there default value guaranteed to be NULL by default? Or do I have to speficy this manually:

report = models.FileField(upload_to='reports', null=True, default=None)
                                                          ^^^^^^^^^^^^

I couldn't found anything about it in the documentation about models fields.

Était-ce utile?

La solution

Not quite:

django/db/models/fields/__init__.py

class NOT_PROVIDED:
    pass

class Field(RegisterLookupMixin):
    # some code
    def __init__(..., default=NOT_PROVIDED, ...):

which basically means it is whatever it is in database. For example if you create your table and you set default value directly in database (without altering models), then it will use the value from the database.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top