Null=true the field in the database can be NULL when you add data to the Blank=true Django Admin
Original:
Today, when doing database design, the following user table was designed, where I set the email and phone fields to allow null:
1 class User (models. Model): 2 username = models. Charfield (' username ', max_length=50) 3 password = models. Charfield (' password ', max_length=255) 4 email = models. Emailfield (' mailbox ',null=True) 5 phone = models. Charfield (' phone ', max_length=11,null=True) 6 7 group = models. Manytomanyfield (usergroup,verbose_name= ' user Group ') 8 9 create_date = models. Datetimefield (' Creation time ', auto_now_add=true) update_date = models. Datetimefield (' Last Modified time ', auto_now=true)
But when I add data using Django background management, I find that I can't enter an empty field, and I still need to enter the content.
When you use Django to design a database table, the data is not known
If you set null=true, it only means that the field in the database can be empty, but you still need to enter a value when adding data using background management, because Django automatically does the data validation does not allow the field to be empty
If you want to save a field as a null value in Django, you need to add another parameter: blank=true
In general, it is:
Null=true the field in the database can be NULL when you add data to the Blank=true Django Admin
Therefore, to implement adding null values in Django background management, you should design the table as follows:
1 class User (models. Model): 2 username = models. Charfield (' username ', max_length=50) 3 password = models. Charfield (' password ', max_length=255) 4 email = models. Emailfield (' mailbox ',null=true,blank=True) 5 phone = models. Charfield (' phone ', max_length=11,null=true,blank=True) 6 7 group = models. Manytomanyfield (usergroup,verbose_name= ' user Group ') 8 9 create_date = models. Datetimefield (' Creation time ', auto_now_add=true) update_date = models. Datetimefield (' Last Modified time ', auto_now=true)
Originating From: http://www.cnblogs.com/MacoLee/p/5610989.html
How fields are empty in the Django database design