Django makemigrations work, migration fails with "django.db.utils.IntegrityError: NOT NULL constraint failed"

I am stuck. Django 1.7, SQLite3.

I modified my model to add a thumbnail column, as in this tutorial . It was like this:

 from django.db import models class Article(models.Model): title = models.CharField(max_length=200) body = models.TextField() pub_date = models.DateTimeField('date published') likes = models.IntegerField(default=0) def __str__(self): return self.title 

and now this:

 from django.db import models from time import time def get_upload_file_name(instance, filename): return "uploaded_files/%s_%s" % (str(time()).replace(".", "_"), filename) class Article(models.Model): title = models.CharField(max_length=200) body = models.TextField() pub_date = models.DateTimeField('date published') likes = models.IntegerField(default=0) thumbnail = models.FileField(upload_to=get_upload_file_name, null=True) def __str__(self): return self.title 

I copied all the data to a json text file using

 python manage.py dumpdata article --indent=4 > article.json 

and then do

 python manage.py makemigrations 

who worked. But

 python manage.py migrate 

not working with

django.db.utils.IntegrityError: NOT NULL constraint failed: article_article__new.thumbnail

And now, even after adding null=True to the thumbnail line in models.py , makemigrations completed successfully, and migrate failed.

What should I do?

+7
python django sqlite
source share
1 answer

My application name (created using python manage.py startapp ) is called articles . Here is the new articles\migrations folder, after receiving an error with a type restriction several times:

 __init__.py 0001_initial.py 0002_auto_20140803_1540.py 0003_auto_20140803_1542.py 0004_auto_20140803_1450.py 0005_auto_20140803_1552.py __pycache__ __init__.cpython-34.pyc 0001_initial.cpython-34.pyc 0002_auto_20140803_1540.cpython-34.pyc 0003_auto_20140803_1542.cpython-34.pyc 0004_auto_20140803_1450.cpython-34.pyc 0005_auto_20140803_1552.cpython-34.pyc 

I deleted all 000 * files in both directories except 0001.

Then i ran

 python manage.py makemigrations 

and

 python manage.py migrate 

successfully.

Thank you for irc.freenode.net/django .

+15
source share

All Articles