I have added a new field in my model but after that I have deleted db.sqlite3 (to ensure I don't get error below)
agrawalo@:~/myapp> ls
README.md config core manage.py requirements.txt
But still I get this error when I run makemigrations
# ./manage.py makemigrations
You are trying to add a non-nullable field 'high52' to stock 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
You can either provide a default value to the field
high52 = models.DecimalField(max_digits=19, decimal_places=2, default=0.0)
or you can make it optional
high52 = models.DecimalField(max_digits=19, decimal_places=2, null=True, blank=True)
You can make a decision based on your choice.
To answer your question about the error, the previously existing fields might have been created in the initial migration itself and they don't need a default value. But for the newly added field, you need a default value for mandatory fields and this default value will be populated in the existing records. This doesn't depend on whether you have deleted the existing database or not. This depends on the current state of migrations for that model. Since this is not the initial migration, you will need to provide a default value or make it optional.
[root@cnwbzp3137 aiaanzreport]# /home/shensh/snowreport/bin/python3 manage.py makemigrations
You are trying to add a non-nullable field 'prduedate' to pr 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 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
Type 'exit' to exit this prompt
>>> Null
Invalid input: name 'Null' is not defined
>>> 'null'
Migrations for 'AIASSHK':
AIASSHK/migrations/0003_pr_prduedate.py