I set default value as 0 in foreign key field in Django model. But it is raising IntigrityError (1048, “Column ‘country_id’ cannot be null”)
Hi, I have code like:
class TestModel(models):
name = models.CharField(max_length=255, blank=True)
reg_from = models.CharField(max_length=255, blank=True)
gender = models.CharField(max_length=1, choices=GENDER_CHOICES, blank=True, null=True)
country = models.ForeignKey(Country, blank=True, default=0)
For some reason, while saving TestModel, I can’t provide country information. I would like to update that later.
Krish
I made field null as quick and dirty solution.