0👍
This was caused because you’re trying to migrate a model field that cannot be null, but since it cannot be null, it needs a default value so that django can replace all the existing rows with the null value of that field.
You have two options:
-
Provide the default by hand, and the django it’s going to replace all the null values of that field with this
-
Set a default value in the model, example:
number = models.IntegerField(default=1)
string = models.CharField(default='')
1👍
first approach
- this comes because you run the migration on each field created so the previous created filled doesn’t accept null value so you want to provide default value in your case it is string value
- you can choose the first choice and but the answer to be "default" with a quotation to understand it as a string
The second solution
delete the latest file created in the migration folder and
modify your model to be
'''
name = models.CharField(max_length=100,null=True)
details = models.CharField(max_length=500, null=True)
'''
then run the migration again
python manage.py makemigration
python manage.py migrate
then go back to model again and remove null from each field and run
python manage.py makemigration
python manage.py migrate
- [Answered ]-Django DateInput() Widget appears in Chrome, but not Firefox or IE
- [Answered ]-Python cant make dictionary from list of dictionaries
- [Answered ]-Django link to a specific users profile page
- [Answered ]-Django, South: I get a warning with key length while indexing
- [Answered ]-Trying to exit out of a function in Django in order to render correct html page name