Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django refuses to accept my one-off default value for FloatField

Tags:

python

django

I have a class and I'm trying to add a new FloatField to it. Django wants a default value to populate existing rows (reasonable). However, it refuses to accept any value I give it.

You are trying to add a non-nullable field 'FIELDNAME' to CLASS without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
 1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
 2) Quit, and let me add a default in models.py
Select an option: -1
Please select a valid option: -1
Please select a valid option: -1
Please select a valid option: float(-1)
Please select a valid option: -1.0
Please select a valid option: float(-1.0)
Please select a valid option: 

How do I get it to accept my value?

like image 317
CoderGuy123 Avatar asked Sep 08 '16 17:09

CoderGuy123


1 Answers

You should select option 1 and then input your value

 1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
 2) Quit, and let me add a default in models.py
 1

After selecting 1. It would ask to provide your default value.

Please enter the default value now, as valid Python
The datetime and django.utils.timezone modules are available, so you can do e.g. timezone.now()
>>> -1.0 
like image 134
levi Avatar answered Nov 14 '22 21:11

levi