1

I am putting an image field in a model called Students. Everything is working fine until I put an image field into the model. I am getting the following even I put blank and null as True. It should work fine. Following is the detail information.

Error

django.db.utils.IntegrityError: NOT NULL constraint failed: new__genius_students.image

This is the model

models.py

class Students(models.Model):
    created_by = models.ForeignKey(
        User, on_delete=models.SET_NULL, default=1, null=True)
    name = models.CharField(max_length=200, null=True)
    image = models.ImageField(upload_to='images/', null=True, blank=True)
    dob = models.DateField(null=True, verbose_name='Date of Birth')
    age = models.IntegerField()

I had tried many things like clearing cache and cookie. But No luck.

Community
  • 1
  • 1
Vikrant Agrahari
  • 133
  • 2
  • 11
  • 1
    Possible duplicate of https://stackoverflow.com/questions/42733221/django-db-utils-integrityerror-not-null-constraint-failed-products-product-ima – abhijeetviswa Apr 30 '20 at 13:33

1 Answers1

1

Go to the migrations folder and delete manually files that have 000*_lastAction_blah-blah type of name, you can delete, probably all, but 0001_initial.py file. After that run ./manage.py make migrations app_you_are_updateing, it should update your database.

officialrahulmandal
  • 2,473
  • 1
  • 23
  • 31
  • 2
    good to hear that. can you mark my answer as accepted..? It would be helpful for other folks so that they get to know that this is a working solution. :-) – officialrahulmandal Apr 30 '20 at 13:39