syncdb not adding fixtures in 3rd party project

大兔子大兔子 提交于 2020-01-06 23:42:10

问题


I've written a pretty simple Django application called django-locality which takes the headache out of working with countries and territories. It provides a lot of initial data for countries and territories. I just the 0.1 release up to PyPI, and installed it in my project which I'm currently working on. (I basically created it out of a need I found in my original project.)

When I ran syncdb, however, it didn't install any of my fixtures from locality. In the output, it printed "No fixtures found," and no rows were added to the database, though the tables were generated. Is there a reason why Django is missing my initial data? My data lives at locality/fixtures/initial_data.json and installs just fine if running it from it's own dedicated project. As I'm using setuptools to manage dependencies, would it make a difference if I downloaded it as a zipped egg vs. a simple directory layout?


Initially, it seems that my JSON wasn't being included in the egg, and this is why syncdb didn't work. Now, I've fixed that problem, but syncdb is still failing to find any of my fixtures. You can download the egg to see for yourself here. I can't think of any reason why Django would be missing the initial data. You can also view the repository on GitHub. Why isn't Django seeing the fixtures?


When I run syncdb -v 2, I do see that Django sees the egg and looks for the fixtures:

No json fixture 'initial_data' in '/home/rfkrocktk/Desktop/myproject/eggs/django_locality-0.1.1-py2.7.egg/locality/fixtures'.

Is it possible that Django doesn't know how to read from eggs?


回答1:


It looks like your setup.py does not include the initial_data.json as package_data: http://docs.python.org/distutils/setupscript.html#installing-package-data This means when you install from PyPi you won't get the initial_data.json file in your distribution.

I personally find it easier to use source distributions sdist for Django apps. In that case you can list non-Python files which need to be included in the MANIFEST: http://docs.python.org/distutils/sourcedist.html




回答2:


Ok, as it turns out, Django doesn't know how to look inside zipped egg files. As soon as I extracted the egg file to a directory with its name, things worked.



来源:https://stackoverflow.com/questions/8317835/syncdb-not-adding-fixtures-in-3rd-party-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!