我已经成功创建了我的第一个django项目。django grok YML? django不加载装置YML文件(yml不是已知的序列化)
我在我的项目foo和foobar中有两个应用程序。
我在每个应用程序文件夹中都创建了一个名为'fixtures'的文件夹。我没有在settings.yml中指定fixtures目录,因此(according to the docs),django应该在我的{app}/fixtures文件夹中查找。
在{app}/fixtures文件夹中,我有几个YML文件。我将各个模块的初始数据拆分为单独的YML文件,确保没有跨文件依赖关系(即,所有相关模型都位于相同的YML文件中,祖先在使用它们的模型之前出现在文件中)。
然而,当我run./manage.py执行syncdb成功创建了分贝对象后,有以下信息:
未发现夹具
然后我试图手动加载夹具通过使用loaddata命令:
./manage.py loaddata 0100_foobar.yml
Problem installing fixture '0100_foobar': yml is not a known serialization
是在上述错误给出的链接文件?或者我需要为安装模块Django的神交YML?
顺便说一句,在YML文件解析正常,并已检查正确性(我用他们成功地在其他项目中) - 所以这不是问题
[编辑]
我已经安装了PyYaml并根据Manoj的说明将我的灯具文件重新命名。我能够得到更多的线,但我仍然遇到问题(顺便说一句,我使用PyYaml 3.0.9)。
这是在我的项目ORM(即{}应用/model.py)型号:
class Currency(models.Model):
short_name = models.CharField(max_length=3, db_index=True, unique=True, null=False) # ISO Code
long_name = models.CharField(max_length=64, db_index=True, unique=True, null=False)
spot_settle = models.IntegerField(null=False, default=0)
rounding = models.IntegerField(null=False, default=2)
这里是YAML文件我进口:
Currency:
currency_aud : { short_name: AUD , long_name: Australia - Dollars , spot_settle: 0, rounding: 2 }
currency_cad : { short_name: CAD , long_name: Canada - Dollars , spot_settle: 0, rounding: 2 }
currency_eur : { short_name: EUR , long_name: Euro Member Countries - Euro , spot_settle: 0, rounding: 2 }
currency_gbp : { short_name: GBP , long_name: United Kingdom - Pounds , spot_settle: 0, rounding: 2 }
currency_jpy : { short_name: JPY , long_name: Japan - Yen , spot_settle: 0, rounding: 2 }
currency_usd : { short_name: USD , long_name: United States Of America - Dollars , spot_settle: 0, rounding: 2 }
currency_zar : { short_name: ZAR , long_name: South Africa - Rand, spot_settle: 0, rounding: 2 }
currency_hkd : { short_name: HKD , long_name: Hong Kong Dollar, spot_settle: 0, rounding: 2 }
currency_nzd : { short_name: NZD , long_name: New Zealand Dollar, spot_settle: 0, rounding: 2 }
currency_sgd : { short_name: SGD , long_name: Singapore Dollar, spot_settle: 0, rounding: 2 }
currency_dkk : { short_name: DKK , long_name: Danish Krone, spot_settle: 0, rounding: 2 }
currency_sek : { short_name: SEK , long_name: Swedish Krona, spot_settle: 0, rounding: 2 }
currency_chf : { short_name: CHF , long_name: Swiss Franc, spot_settle: 0, rounding: 2 }
这里是堆栈跟踪当我运行./manage.py loaddata myapp /灯具/货币.yaml
[email protected]:~/work/demo/myproj$ ./manage.py loaddata reference/fixtures/0100_currency.yaml
Installing yaml fixture 'reference/fixtures/0100_currency' from absolute path.
Problem installing fixture 'reference/fixtures/0100_currency.yaml': Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/django/core/management/commands/loaddata.py", line 165, in handle
for obj in objects:
File "/usr/local/lib/python2.6/dist-packages/django/core/serializers/pyyaml.py", line 57, in Deserializer
for obj in PythonDeserializer(yaml.load(stream), **options):
File "/usr/local/lib/python2.6/dist-packages/django/core/serializers/python.py", line 84, in Deserializer
Model = _get_model(d["model"])
TypeError: string indices must be integers, not str
我已投票结束了它。希望其他人会同意并删除它。 – 2010-10-07 11:02:05
感谢Manoj。我以为我有答案,但事实证明我错了,所以我再次重新提交了这个问题,稍作修改以反映我的新发现 – skyeagle 2010-10-07 11:03:52
oops。不幸的是我不能撤回我的投票。 – 2010-10-07 11:04:43