سؤال

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top