Adding django model default values after creation
I created a model similar to the following:
class Pick(models.Model):
user = models.ForeignKey(User)
team = models.ForeignKey(Team)
week = models.IntegerField()
result = models.IntegerField()
This worked great until I wanted to add a default value to result. I made the following change:
result = models.IntegerField(default=3)
I still get a 'Field required' error when trying to add a new Pick. I don't want to destroy the database, if possible. I tried adding a default value straight into mysql but I think the model default values are checked in code before going to the db. What's the best way to get this default value working?
EDIT: ok, so I feel like a moron; I don't know what was going on but I was modifying the model in my IDE and nothing was working. I tried modifying the help_text (which I didn't include in my examples) and that wasn't changing either. I eventually went to the command line and realized that I hadn't bee开发者_如何学Gon changing the file at all. I still have no idea what happened, as I have been making all changes through the IDE. So it appears that I am just crazy after all. Thanks for all the comments as it helped me search for a solution outside the normalities of the code.
Can you add 'required=False' to a specific field on a form you are using?
精彩评论