Jglstewart
Jglstewart

Reputation: 706

Django 1.7 - allow null and blank in the database, but do not allow null or blank in admin form

I have a database where I have older entries which contain null/blank values for a specific field. However, from now on, I would like to not allow null/blank values to be added to the database.

Is there a way to do this in Django 1.7, python 3.4.

Upvotes: 0

Views: 53

Answers (2)

shellbye
shellbye

Reputation: 4858

We did this just by change the Model field to not allow null/blank and add default value, and also write a script to add default value to the already existed data whose field is null/blank.

Upvotes: 0

knbk
knbk

Reputation: 53699

There's really no such thing as blank in the database, or null in the admin. null controls whether the database can contain NULL values (not even empty values, just NULL). blank controls whether the admin and modelforms accept empty values.

It seems to me that what you want is simply null=True, blank=False.

Upvotes: 1

Related Questions