Database validation error - Even after manage.py flush.

89 views
Skip to first unread message

pieceof...@gmail.com

unread,
Jun 30, 2017, 1:23:39 PM6/30/17
to Django users
So I made the ultimate error.  I put a BooleanField in my models.py, when I made migrations I set default col value to the empty string ''.. Then I migrated and got a validation error.  However, I have tried to delete the model containing BooleanField, delete my database file, and I even ran manage.py flush and cannot seem to get rid of this error.  If anyone has any experience with BooleanField errors please help.  My traceback from my terminal is below:

  Applying build_a_bundle.0012_auto_20170630_1027...Traceback (most recent call last):
 
File "manage.py", line 22, in <module>
    execute_from_command_line
(sys.argv)
 
File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility
.execute()
 
File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute
   
self.fetch_command(subcommand).run_from_argv(self.argv)
 
File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
   
self.execute(*args, **cmd_options)
 
File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 330, in execute
    output
= self.handle(*args, **options)
 
File "/usr/lib64/python2.7/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial
=fake_initial,
 
File "/usr/lib64/python2.7/site-packages/django/db/migrations/executor.py", line 115, in migrate
    state
= self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
 
File "/usr/lib64/python2.7/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
    state
= self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
 
File "/usr/lib64/python2.7/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state
= migration.apply(state, schema_editor)
 
File "/usr/lib64/python2.7/site-packages/django/db/migrations/migration.py", line 129, in apply
    operation
.database_forwards(self.app_label, schema_editor, old_state, project_state)
 
File "/usr/lib64/python2.7/site-packages/django/db/migrations/operations/fields.py", line 86, in database_forwards
    field
,
 
File "/usr/lib64/python2.7/site-packages/django/db/backends/sqlite3/schema.py", line 238, in add_field
   
self._remake_table(model, create_field=field)
 
File "/usr/lib64/python2.7/site-packages/django/db/backends/sqlite3/schema.py", line 113, in _remake_table
   
self.effective_default(create_field)
 
File "/usr/lib64/python2.7/site-packages/django/db/backends/base/schema.py", line 229, in effective_default
   
default = field.get_db_prep_save(default, self.connection)
 
File "/usr/lib64/python2.7/site-packages/django/db/models/fields/__init__.py", line 766, in get_db_prep_save
    prepared
=False)
 
File "/usr/lib64/python2.7/site-packages/django/db/models/fields/__init__.py", line 758, in get_db_prep_value
    value
= self.get_prep_value(value)
 
File "/usr/lib64/python2.7/site-packages/django/db/models/fields/__init__.py", line 1039, in get_prep_value
   
return self.to_python(value)
 
File "/usr/lib64/python2.7/site-packages/django/db/models/fields/__init__.py", line 1032, in to_python
   
params={'value': value},
django
.core.exceptions.ValidationError: [u"'' value must be either True or False."]



Guilherme Leal

unread,
Jun 30, 2017, 1:37:26 PM6/30/17
to django...@googlegroups.com
>>>>>>>django.core.exceptions.ValidationError: [u"'' value must be either True or False."]


Have you tried to set the default value of the BooleanField as True or False? BooleanFields must have a valid boolean as default value and so happends that empty string is not a valid boolean.

Change the default value to False (as exemple), run the migration again, and it should work.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dc30ad69-a4b8-4163-8f7e-7a5d0d42fbd8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

pieceof...@gmail.com

unread,
Jun 30, 2017, 2:03:32 PM6/30/17
to Django users
Yes.  At first I tried setting default=True or default=False for my BooleanField and kept getting the same error.  So I went back in, deleted the model, tried again, got the same error.  Then I deleted my db sqlite3 file, made new migrations, migrated (with the model not even a part of my models.py anymore) and am still getting this error. 

pieceof...@gmail.com

unread,
Jun 30, 2017, 2:04:36 PM6/30/17
to Django users
I also did the "If all else fails, reboot your computer" and still have the same problem.  Haha.  I think I'm screwed.

Guilherme Leal

unread,
Jun 30, 2017, 2:09:21 PM6/30/17
to django...@googlegroups.com
Have you re-ran the "makemigrations"? If that didnt work, delete the migration file (0012_auto_20170630_1027) and run "makemigrations" again.

2017-06-30 15:04 GMT-03:00 <pieceof...@gmail.com>:
I also did the "If all else fails, reboot your computer" and still have the same problem.  Haha.  I think I'm screwed.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Guilherme Leal

unread,
Jun 30, 2017, 2:10:32 PM6/30/17
to django...@googlegroups.com
Just to clarify:

Change the default value to "False";
Delete the migration file (0012_auto_20170630_1027);
Run makemigrations;
Run migrate.

pieceof...@gmail.com

unread,
Jun 30, 2017, 2:16:40 PM6/30/17
to Django users

Oh dude you are officially my hero!  I didn't even think about the migration files.  That totally worked.  And thank you thank you thank you =D <3.

Guilherme Leal

unread,
Jun 30, 2017, 2:23:25 PM6/30/17
to django...@googlegroups.com
Np man, always glad to help!

Just to seal the case, that happened because django dont edit the migration files itself (well, not through the normal cycle of "makemigrations">"migrate"). You generated a migration with an invalid config, and didnt even mattered if you tried to correct that "default value" and generated another migration, the incorrect migration would still be there.

Another thing that should work would be to generate another migration with the fix for the default value, and use the "squash migrations" feature, which would persist only the most recent/relevant "default value" for that field.

2017-06-30 15:16 GMT-03:00 <pieceof...@gmail.com>:

Oh dude you are officially my hero!  I didn't even think about the migration files.  That totally worked.  And thank you thank you thank you =D <3.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

pieceof...@gmail.com

unread,
Jun 30, 2017, 2:47:23 PM6/30/17
to Django users
Hey thanks for that extra input.  I'm currently a student at NMSU making an educational app for NASA'S Planetary Data Systems.  Right now I'm the only student working on it and the only person in my building that knows Django (which I'm learning on the job).  I'm making a blog alongside my app to supplement the Django tutorials and reading material we have for the following students we bring onto this project.  I've read through my books like 20 times already and since they're beginner level books there really isn't too much in depth material about migrations or databases in Django.  So this post will definitely be pinned in our student blog.  You the man Guilherme! 

Guilherme Leal

unread,
Jun 30, 2017, 3:01:54 PM6/30/17
to django...@googlegroups.com
Hey man, if you have any problem, ALWAYS check the django documentation in the first place. IMO, its preaty extensive and complete, and always helped me through the 4~5 years I'm developing with django.

After that, stackoverflow always help ( =P ).

And if the things still goes badly, django-users will help too. The answer might take a while, but will always come (I gess).

2017-06-30 15:47 GMT-03:00 <pieceof...@gmail.com>:
Hey thanks for that extra input.  I'm currently a student at NMSU making an educational app for NASA'S Planetary Data Systems.  Right now I'm the only student working on it and the only person in my building that knows Django (which I'm learning on the job).  I'm making a blog alongside my app to supplement the Django tutorials and reading material we have for the following students we bring onto this project.  I've read through my books like 20 times already and since they're beginner level books there really isn't too much in depth material about migrations or databases in Django.  So this post will definitely be pinned in our student blog.  You the man Guilherme! 

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages