[Fixed]-How to set default value for FloatField in django model

21👍

Your code should work. Perhaps something is setting the empty value to a non-null value (like an empty string). I’d have to see the full error message.

Since this is an old thread, I’m going to post the answer to the question I came here for, “How do you set FloatField default to Null in the database?”

cost = models.FloatField(null=True, blank=True, default=None)

10👍

Float Field is quite related to Decimal Field so, probably it should take a default argument. Try doing this..

cost = models.FloatField(default=to_some_value)

Leave a comment