IntegrityError --- NOT NULL constraint failed: books_book.publication_date

2,060 views
Skip to first unread message

Sami Razi

unread,
Mar 26, 2014, 11:31:38 AM3/26/14
to django...@googlegroups.com
  
 i'm learning django using djangobook, in chapter 6, i'm having this error:

      IntegrityError at /admin/books/book/add/

      NOT NULL constraint failed: books_book.publication_date


it seems i should set null=True for publication_date field. but i did it already, this is my models.py:


from django.db import models

class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()

def __unicode__(self):
return self.name

class Author(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
email = models.EmailField(blank=True, verbose_name='e-mail')

def __unicode__(self):
return u'%s %s' % (self.first_name, self.last_name)

class Book(models.Model):
title = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)
publisher = models.ForeignKey(Publisher)
publication_date = models.DateField(blank=True, null=True)

def __unicode__(self):
return self.title



what am i doing wrong?
i googled the error message but didn't find a related answer.
thank you for your help.

Sam Walters

unread,
Mar 26, 2014, 11:40:03 AM3/26/14
to django...@googlegroups.com
Did you perhaps change the schema of the database after you had created it.

Eg: added null=True as a constraint after creating the table?

If so check the db sheme using:
python manage.py sqlall <appname>

It sounds simple enough. You will have to go into the db shell and update your schema manually.

using

python manage.py dbshell

If you're developing something where the schema is always getting modified and you dont want to manually update table constraints
look into

django south addon.

hope this helps


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/87ef0e56-f90f-4097-8a2c-e747ac874b71%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages