I am working on a project where I originally intended some fields to be required that are now optional. However, the newer fields will still throw an error if they are left blank.
From my models.py:
class PlanOfAction(models.Model):
PoA_1 = models.CharField(max_length=255, blank=True, default="")
q1_why = models.CharField(max_length=255, blank=True, default="")
PoA_2 = models.CharField(max_length=255, blank=True, default="yeah")
q2_why = models.CharField(max_length=255, blank=True, default="")
PoA_3 = models.CharField(max_length=255, blank=True, default="")
q3_why = models.CharField(max_length=255, blank=True, default="")
long_term_goal = models.CharField(max_length=255, blank=True, default="")
long_term_date = models.CharField(max_length=255, blank=True, default="")
long_term_actions_1 = models.CharField(max_length=255, blank=True, default="")
long_term_actions_2 = models.CharField(max_length=255, blank=True, default="")
long_term_actions_3 = models.CharField(max_length=255, blank=True, default="")
short_term_1 = models.CharField(max_length=255, blank=True, default="")
short_term_1_date = models.CharField(max_length=255, blank=True, default="")
short_term_actions_1_1 = models.CharField(max_length=255, blank=True, default="")
short_term_actions_1_2 = models.CharField(max_length=255, blank=True, default="")
short_term_actions_1_3 = models.CharField(max_length=255, blank=True, default="")
created_by = models.ForeignKey(User, related_name="user_poa")
objects = PlanManager()
created_at = models.DateTimeField(auto_now_add = True)
updated_at = models.DateTimeField(auto_now = True)
And where it is writing to the database in models.py
new_plan = PlanOfAction.objects.create(
PoA_1 = POST['PoA_1'],
q1_why = POST['q1_why'],
PoA_2 = POST['PoA_2'],
q2_why = POST['q2_why'],
PoA_3 = POST['PoA_3'],
q3_why = POST['q3_why'],
long_term_goal = POST['long_term_goal'],
long_term_date = POST['long_term_date'],
long_term_actions_1 = POST['long_term_actions_1'],
long_term_actions_2 = POST['long_term_actions_2'],
long_term_actions_3 = POST['long_term_actions_3'],
short_term_1 = POST['short_term_goal_1'],
short_term_1_date = POST['short_term_1_date'],
short_term_actions_1_1 = POST['short_term_actions_1_1'],
short_term_actions_1_2 = POST['short_term_actions_1_2'],
short_term_actions_1_3 = POST['short_term_actions_1_3'],
created_by = User.objects.get(id=id),
)
If I leave the short term actions blank, I get no errors. I did add these in later, and initially set them with blank=True and default="". After updating the other fields I deleted the migrations folder, db.sqlite3, run migrate, makemigrations, then migrate again. I error every time on PoA_2 = POST['PoA_2'] if that field is blank.
MultiValueDictKeyError at /view_your_plan
"u'PoA_2'"
Any ideas?
Using Python 2.7.