Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBRIAN WEBER
21,570 Pointsdjango.db.utils.OperationalError: (1067, "Invalid default value for 'age'") - Deploying Pug or Ugh API App
I run this command python manage.py migrate --settings=backend.deploy_settings
then I get the following error when trying to migrate over to a MySQL database:
django.db.utils.OperationalError: (1067, "Invalid default value for 'age'")
Here is my Dog
model in the models.py file:
from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import post_save
class Dog(models.Model):
"""Dog model class."""
GENDER_CHOICES = (
('m', 'male'),
('f', 'female'),
('u', 'unknown'),
)
SIZE_CHOICES = (
('s', 'small'),
('m', 'medium'),
('l', 'large'),
('xl', 'extra large'),
('u', 'unknown'),
)
name = models.CharField(max_length=255, default='Unknown name')
image_filename = models.CharField(max_length=255, default='')
breed = models.CharField(max_length=255, default='Unknown mix')
age = models.IntegerField(default=1, blank=True, null=True)
gender = models.CharField(
max_length=1,
choices=GENDER_CHOICES,
default='Unknown gender'
)
size = models.CharField(
max_length=2,
choices=SIZE_CHOICES,
default='Unknown size'
)
neutered = models.BooleanField(default=False)
def __str__(self):
return self.name
Any help would be appreciated! Thank you.
Brian
1 Answer
Kenneth Love
Treehouse Guest TeacherHmm, that's a weird error and I'm not sure why you're getting it. I'd remove the null=True
on that field, though, since it won't ever be null (you have a default value).
On your gender
and size
fields, your default value is much longer than your max_length
. Probably want to fix that.
BRIAN WEBER
21,570 PointsBRIAN WEBER
21,570 PointsGood catch on the
gender
andsize
fieldmax_length
setting. I updated and pushed my changes to GitHub.As for the error I am getting switching over to a MySQL database, I'll have to investigate further to see why I am getting a default value error for age.