Vikrant Agrahari
Vikrant Agrahari

Reputation: 163

How to fix Django models migrate error for image field?

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.

Upvotes: 1

Views: 628

Answers (1)

officialrahulmandal
officialrahulmandal

Reputation: 3118

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.

Upvotes: 1

Related Questions