3👍
Others are right. you should set a default value for that field.
but there is a a trick that you can solve this. but it is not a good way… only if you have no choice.
1. comment all of your table
2. run makemigrations
and migrate
3. uncomment your table
4.2. run makemigrations
and migrate
again
3👍
image1=models.ImageField(upload_to='app/image12',help_text="hi", null=True)
That is, set null= True'
in the field.
It happens when you change your model after stored database.
0👍
If you want to make it non nullable without default.
you have to provide value for the same field when you create migration file. thats why it asks for the option. type “1” in terminal while python manage.py makemigrations and then provide a value for the field for previously saved row(if any).
Let me know if this helps.
- [Django]-Django rest framework viewset permission based on method
- [Django]-Django pagination overhead with sorting
- [Django]-Passing context from child to parent template in Django
- [Django]-Handle OPTIONS request with django's built in server
- [Django]-SPEED UP Django Form to Upload large (500k obs) CSV file to MySQL DB
0👍
I have faced a same issue, in my case:
Focus on the alert:
…non-nullable field ‘comment’ to family…
- model: Family
- field: comment
Just add one more attr in the field comment of the model family:
default=''
- [Django]-DRF how to save a model with a foreign key to the User object
- [Django]-Retrieve the integer stored in (?P<topic_id>\d+)
- [Django]-Django form.save(commit=False) not adding user_id
- [Django]-Crontab is running but still not executing command Django
- [Django]-How to get logged in username in views.py in django
0👍
Just select option 1
. Then set a default.
It will create a migration script with the property preserve_default=False
which means the default is used only for the migration. It will not affect the default settings in the database.
https://docs.djangoproject.com/en/4.2/ref/migration-operations/#alterfield
- [Django]-Object permission function firing more than once
- [Django]-Populate() isn't reentrant Django Google App Engine
- [Django]-Python django create own command and add list as parameter
- [Django]-Query multiple models with class-based views
-1👍
You can add this: default=None
or default="something"
or add null=True
, blank=True
.
- [Django]-Django: Add number of results
- [Django]-Does Django ModelForm set unspecified fields to empty?
- [Django]-TypeError: 'UniqueConstraint' object is not iterable in Django
- [Django]-Django Loading Templates with Inheritance from Specific Directory