Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.3K
Vistas
django.db.utils.IntegrityError: NOT NULL constraint failed: products_product.image ERROR WITH IMAGE FIELD

I wanna add imagefield to my models.py and upload in my media_cdn directory but when i migrate to base my model.py he give this error

django.db.utils.IntegrityError: NOT NULL constraint failed: products_product.image ERROR WITH IMAGE FIELD

Output from cmd

operation.database_forwards(self.app_label, schema_editor, old_state, project_state)

File "C:\Users\PANDEMIC\Desktop\td10\lib\site-packages\django\db\migrations\operations\fields.py", line 84, in database_forwards field, File "C:\Users\PANDEMIC\Desktop\td10\lib\site-packages\django\db\backends\sqlite3\schema.py", line 231, in add_field self._remake_table(model, create_fields=[field]) File "C:\Users\PANDEMIC\Desktop\td10\lib\site-packages\django\db\backends\sqlite3\schema.py", line 199, in _remake_table self.quote_name(model._meta.db_table), File "C:\Users\PANDEMIC\Desktop\td10\lib\site-packages\django\db\backends\base\schema.py", line 112, in execute cursor.execute(sql, params) File "C:\Users\PANDEMIC\Desktop\td10\lib\site-packages\django\db\backends\utils.py", line 79, in execute return super(CursorDebugWrapper, self).execute(sql, params) File "C:\Users\PANDEMIC\Desktop\td10\lib\site-packages\django\db\backends\utils.py", line 64, in execute return self.cursor.execute(sql, params) File "C:\Users\PANDEMIC\Desktop\td10\lib\site-packages\django\db\utils.py", line 94, in exit six.reraise(dj_exc_type, dj_exc_value, traceback) File "C:\Users\PANDEMIC\Desktop\td10\lib\site-packages\django\utils\six.py", line 685, in reraise raise value.with_traceback(tb) File "C:\Users\PANDEMIC\Desktop\td10\lib\site-packages\django\db\backends\utils.py", line 64, in execute return self.cursor.execute(sql, params) File "C:\Users\PANDEMIC\Desktop\td10\lib\site-packages\django\db\backends\sqlite3\base.py", line 337, in execute return Database.Cursor.execute(self, query, params) django.db.utils.IntegrityError: NOT NULL constraint failed: products_product.image

from django.db import models

# Create your models here.

class Product(models.Model):
    name = models.CharField(max_length=40)
    description = models.TextField(max_length=220, blank=True, default=None)
    image = models.ImageField(upload_to="/products_images/", null=True, blank=True, width_field="width_field", height_field="height_field")
    width_field = models.IntegerField(default=0)
    height_field = models.IntegerField(default=0)
    is_active = models.BooleanField(default=True)
    publish = models.DateField(auto_now=False, auto_now_add=True)
    timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)

    def __str__(self):
        return "%s" % self.id

    class Meta:
        ordering = ["-timestamp"]
        verbose_name = 'Product'
        verbose_name_plural = 'Products'
over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

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.

over 4 years ago · Santiago Trujillo Denunciar

0

need just delete your base and make migrations your app

over 4 years ago · Santiago Trujillo Denunciar

0

Have you ran makemigrations appname yet?

NOT NULL constraint failed

This error usually means that a field that is required was not provided, but I can see that you have set the blank=True and null=True attributes in your image field.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda