syncdb 未在第 3 方项目中添加固定装置

发布于 2024-12-18 18:58:55 字数 1151 浏览 2 评论 0原文

我编写了一个非常简单的 Django 应用程序,名为 django-locality ,它消除了使用时的头痛国家和地区。它提供了许多国家和地区的初始数据。我刚刚发布了 PyPI 的 0.1 版本,并将其安装在我当前正在开发的项目中。 (我基本上是出于在原始项目中发现的需要而创建了它。)

但是,当我运行 syncdb 时,它没有安装来自 locality 的任何装置。在输出中,它打印“未找到固定装置”,并且尽管生成了表,但没有将行添加到数据库中。 Django 丢失我的初始数据是否有原因?我的数据位于 locality/fixtures/initial_data.json 中,如果从自己的专用项目运行它,则安装得很好。由于我使用 setuptools 来管理依赖项,如果我将其下载为压缩的 Egg 与简单的目录布局,会有什么不同吗?


最初,我的 JSON 似乎没有包含在 Egg 中,这就是 syncdb 不起作用的原因。现在,我已经解决了这个问题,但是 syncdb 仍然无法找到我的任何装置。您可以在此处下载该egg并亲自查看。我想不出 Django 会丢失初始数据的任何原因。您还可以在 GitHub 上查看存储库。为什么姜戈看不到赛程?


当我运行 syncdb -v 2 时,我确实看到 Django 看到了 Egg 并寻找固定装置:

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

Django 是否可能不知道如何从 Egg​​ 中读取数据?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暮色兮凉城 2024-12-25 18:58:55

看起来您的 setup.py 不包含 initial_data.json 作为 package_data: http://docs.python.org/distutils/setupscript.html#installing-package-data 这意味着当您从 PyPi 安装时,您将不会在发行版中获得initial_data.json 文件。

我个人发现对 Django 应用程序使用源发行版 sdist 更容易。在这种情况下,您可以列出需要包含在 MANIFEST 中的非 Python 文件: http:// docs.python.org/distutils/sourcedist.html

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

坏尐絯℡ 2024-12-25 18:58:55

好吧,事实证明,Django 不知道如何查看压缩的 Egg 文件的内部。当我将 Egg 文件解压缩到具有其名称的目录时,一切就正常了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文