I'm currently using Django 1.2.4 and MySQL 5.1 on Ubuntu 9开发者_JS百科.10. The model is:
# project/cream/models.py
class IceCream(models.Model):
name = models.CharField(max_length=100)
code = models.CharField(max_length=5)
def __unicode__(self):
return u'%s - %s' % (self.code, self.name)
The fixtures data in a project/cream/fixtures/data.yaml
file is:
- model: cream.icecream
pk: 1
fields:
name: Strawberry
code: ST
- model: cream.icecream
pk: 2
fields:
name: Noir Chocolat
code: NO
From the project folder, I invoke the command:
python manage.py loaddata cream/fixtures/data.yaml
The data is successfully loaded in the database but they look like the following:
False - Noir Chocolat
ST - Strawberry
Notice how the first entry is False
instead of NO
. Does anyone know how to fix this issue in my fixtures?
NO
is treated as False
because PyYaml implicitly detects that as a boolean value, as seen in resolver.py
. If you want it to be the actual string "NO", try putting it in quotes (""
).
精彩评论