Does django grok YML ? django not loading fixtures YML file (yml is not a known serialization) -


i have created first django project.

i have 2 apps in project foo , foobar.

i have created folder named 'fixtures' in each of app folders. have not specified fixtures directory in settings.yml, (according docs), django should looking in {app}/fixtures folder.

in {app}/fixtures folder, have several yml files. have split initial data various modules separate yml files, making sure there no cross file dependencies (i.e. related models in same yml file , ancestors occur in file before models use them).

however, when run./manage.py syncdb after db objects created, there following message:

no fixtures found

i tried manually load fixtures using loaddata command:

./manage.py loaddata 0100_foobar.yml problem installing fixture '0100_foobar': yml not known serialization  

is documentation given in link above wrong?, or need install module in order django grok yml?

btw, yml files parse correctly , have been checked correctness (i used them in project) - not problem

[edit]

i have installed pyyaml , renamed fixtures files per manoj's instructions. able little further down line, still encountering problems (btw, using pyyaml 3.0.9).

here model in project orm (i.e. {app}/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) 

here yaml file importing:

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 } 

here stack trace when run ./manage.py loaddata myapp/fixtures/currencies.yaml

me@somebox:~/work/demo/myproj$ ./manage.py loaddata reference/fixtures/0100_currency.yaml  installing yaml fixture 'reference/fixtures/0100_currency' 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     obj in objects:   file "/usr/local/lib/python2.6/dist-packages/django/core/serializers/pyyaml.py", line 57, in deserializer     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 integers, not str 

i tried reproduce problem in 1 of projects. apparently loaddata expects extension of file match serialization format. in case should rename file 0100_foobar.yaml (note new extension).

local tests showed hypothesis correct.

ps: yaml serialization requires pyyaml library. if haven't, install pyyaml.

update

i copied op's model 1 of projects. when tried load sample yaml given op as-is, got same error.

after added data using admin app , used django.core.serializers.serialize dump data in yaml format.

from django.core.serializers import serialize app.models import currency print serializers.serialize("yaml", currency.objects.all()) 

the result got looked different op posted. see below. added 3 instances model , showing up.

- fields: {long_name: australia - dollars, rounding: 2, short_name: aud, spot_settle: 0}   model: app.currency   pk: 1 - fields: {long_name: canada - dollars, rounding: 2, short_name: cad, spot_settle: 0}   model: app.currency   pk: 2 - fields: {long_name: euro member countries - euro, rounding: 2, short_name: eur,     spot_settle: 0}   model: app.currency   pk: 3 

i able load data without trouble.

given above, suspect there wrong op's yaml file. @skyeagle, can try dumping existing data , then try loading dump back?


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -