Django ForeignKey created empty?

It seems very simple, and I have to skip something, but here anyway ...

With two models like:

class School(models.Model): name = models.CharField("Official School Name", max_length=128) address = models.TextField("Address of the School", max_length=256) mascot = models.CharField("Name of the School Mascot", max_length=128) class StudentProfile(models.Model): name = models.CharField(max_length=128) school = models.ForeignKey(School) 

If a student is created before school, how do I give the "school" the default value is empty? Is it empty or empty or what?

Thanks!

+6
django foreign-keys
source share
1 answer

null if you want the database to allow the relation to be null, blank if you do not want the Django site administrator complaining that it is null.

From the documentation for "blank":

"Please note that this is non-zero. Null is purely database related, while empty is purely related to validation. If the field is empty value = True, validation at the Djangos admin site will allow you to enter an empty value. Has empty = False, the field will be needed. "

In short, you probably need both.

+8
source share

All Articles