Heikki
Heikki

Reputation: 351

Why am I getting `NOT NULL constraint failed` error with Django?

I am new to Django. I am to create some sort of todo app. I am having trouble setting IntegerField as optional field. As far as I can see the problem is when I try to save to save the object to the database. I get error: NOT NULL constraint failed: lista_row.quantity. I have made (and migrated) migrations. Here is my models.py:

from django.db import models
from django.contrib import admin

class Row(models.Model):
    name = models.CharField(max_length=200)
    quantity = models.IntegerField(null=False, blank=True)

Upvotes: 0

Views: 930

Answers (1)

Christian Hansen
Christian Hansen

Reputation: 101

If you want to make it optional, use this instead: quantity = models.IntegerField(blank=True, null=True)

Upvotes: 1

Related Questions