Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
321 views
in Technique[技术] by (71.8m points)

python - Suddenly getting django.core.exceptions.ValidationError when trying to perform db migration in Django of ['“NA” value must be either True or False.']

For weeks I have had no issues making db migrations, and running models. I tried to add a few fields to animals and then I got Validation Error so I removed the fields, but the error remains. I am not sure what the issue is or how to fix it. Prior to trying to add the additional fields (shown below as commented out) I did not have any errors. Now I am getting "django.core.exceptions.ValidationError: ['“NA” value must be either True or False.']". I've looked into the db entries and there are no existing NA entries. I removed from all current fields any default="NA" but I continue to get the error.

What is the source of the error? How can I fix it?

    Operations to perform:
  Apply all migrations: admin, animals, auth, contenttypes, sessions
Running migrations:
  Applying animals.0025_auto_20210111_0214...Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/Users/usr/Desktop/animalDirectoryTemplate/.venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Users/usr/Desktop/animalDirectoryTemplate/.venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/usr/Desktop/animalDirectoryTemplate/.venv/lib/python3.7/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/usr/Desktop/animalDirectoryTemplate/.venv/lib/python3.7/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/Users/usr/Desktop/animalDirectoryTemplate/.venv/lib/python3.7/site-packages/django/core/management/base.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "/Users/usr/Desktop/animalDirectoryTemplate/.venv/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 245, in handle
    fake_initial=fake_initial,
  File "/Users/usr/Desktop/animalDirectoryTemplate/.venv/lib/python3.7/site-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/Users/usr/Desktop/animalDirectoryTemplate/.venv/lib/python3.7/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/Users/usr/Desktop/animalDirectoryTemplate/.venv/lib/python3.7/site-packages/django/db/migrations/executor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Users/usr/Desktop/animalDirectoryTemplate/.venv/lib/python3.7/site-packages/django/db/migrations/migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/Users/usr/Desktop/animalDirectoryTemplate/.venv/lib/python3.7/site-packages/django/db/migrations/operations/fields.py", line 106, in database_forwards
    field,
  File "/Users/usr/Desktop/animalDirectoryTemplate/.venv/lib/python3.7/site-packages/django/db/backends/sqlite3/schema.py", line 328, in add_field
    self._remake_table(model, create_field=field)
  File "/Users/usr/Desktop/animalDirectoryTemplate/.venv/lib/python3.7/site-packages/django/db/backends/sqlite3/schema.py", line 189, in _remake_table
    self.effective_default(create_field)
  File "/Users/usr/Desktop/animalDirectoryTemplate/.venv/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 303, in effective_default
    return field.get_db_prep_save(self._effective_default(field), self.connection)
  File "/Users/usr/Desktop/animalDirectoryTemplate/.venv/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 823, in get_db_prep_save
    return self.get_db_prep_value(value, connection=connection, prepared=False)
  File "/Users/usr/Desktop/animalDirectoryTemplate/.venv/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 818, in get_db_prep_value
    value = self.get_prep_value(value)
  File "/Users/usr/Desktop/animalDirectoryTemplate/.venv/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 967, in get_prep_value
    return self.to_python(value)
  File "/Users/usr/Desktop/animalDirectoryTemplate/.venv/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 960, in to_python
    params={'value': value},
django.core.exceptions.ValidationError: ['“NA” value must be either True or False.']

models.py

    class Animal(models.Model):
        name = models.CharField(max_length=500, blank=False, null=False)
        type = models.ForeignKey(Type, on_delete=models.SET_NULL, blank=False, null=True)
        ageGroup = models.ForeignKey(AgeGroup, max_length=300, on_delete=models.SET_NULL, blank=False, null=True)
        ageYears = models.PositiveIntegerField(blank=False, null=False)
        ageMonths = models.PositiveIntegerField(blank=True, null=True)
        sex = models.CharField(max_length=100, choices=SEX, blank=False, null=False)
        city = models.CharField(max_length=200, blank=True, null=True)
        state = models.CharField(max_length=200, blank=True, null=True)
        country = models.CharField(max_length=250, blank=True, null=True)
        breedGroup = models.ManyToManyField(BreedGroup, blank=False)
        breed = models.ManyToManyField(Breed, blank=False)
        tagLine = models.CharField(max_length=300, blank=False, null=False)
        color = models.CharField(choices=COLORS, max_length=200, blank=False, null=True) #last successful addition 
        weight = models.PositiveIntegerField(blank=False, null=True, default=0) #last successful addition
        # desexed = models.BooleanField(blank=False, null=True)  --> new field 
        # declawed = models.BooleanField(blank=False, null=True) --> new field
        # loverOfTreats = models.PositiveIntegerField(blank=False, null=True) -->new field
        # loverOfGamesPlay = models.PositiveIntegerField(blank=False, null=True) --> new field
        # energyLevel = models.PositiveIntegerField(blank=False, null=True) --> new field
        # pottyTrained = models.BooleanField(blank=False, null=True) --> new field
        goodWithCats = models.BooleanField(blank=False, null=True)
        goodWithCatsScale = models.PositiveIntegerField(blank=True, null=True)
        goodWithDogs = models.BooleanField(null=True, blank=False)
        goodWithDogsScale = models.PositiveIntegerField(blank=True, null=True)
        goodWKids = models.BooleanField(null=True, blank=False)
        goodWithKidsScale = models.PositiveIntegerField(blank=True, null=True)
        history = models.TextField(max_length=1000, null=True, blank=True)
        moreDetails = models.TextField(max_length=1000, null=True, blank=True)
        personality = models.TextField(max_length=1000, null=True, blank=True)
        faqs = models.TextField(max_length=800, null=True, blank=True)
        profilePic = ResizedImageField(size=[300, 450], quality=100, upload_to='media/', default='media/paw.png', null=False, blank=False, keep_meta=False)
        contact = models.ForeignKey(ContactDetails, on_delete=models.SET_NULL, blank=False, null=True)
        created_by = models.ForeignKey(User,related_name="animal", blank=True, null=True, on_delete=models.SET_NULL)
question from:https://stackoverflow.com/questions/65660986/suddenly-getting-django-core-exceptions-validationerror-when-trying-to-perform-d

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...