I scratch my head trying to figure out why a default value is required on some but not all fields. For example the documentation says models.CharField()
has only one mandatory option which is max_length
but python manage.py makemigration
return an error when a default value isn't provided. And I have the same error for some of my models.ForeignKey()
fields. Could you explain why and when a default value should be provided?
models.py
class Algo(models.Model):
strategy = models.ManyToManyField(Strategy, related_name='strategy')
name = models.CharField(max_length=12) # <-- Return an error !?
class Meta:
verbose_name_plural = "algos"
def __str__(self):
return self.name