开发者

Does the value "NO" gets parsed as "False" in MySQL when entered through Django's fixtures?

开发者 https://www.devze.com 2023-02-04 01:23 出处:网络
I\'m currently using Django 1.2.4 and MySQL 5.1 on Ubuntu 9开发者_JS百科.10.The model is: # project/cream/models.py

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 ("").

0

精彩评论

暂无评论...
验证码 换一张
取 消