Django:文本固定装置无法加载
对我的项目进行了转储数据,然后在我的新测试中将其添加到装置中。
from django.test import TestCase
class TestGoal(TestCase):
fixtures = ['test_data.json']
def test_goal(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.failUnlessEqual(1 + 1, 2)
运行测试时我得到:
安装固定装置时出现问题 'XXX/fixtures/test_data.json':
DoesNotExist:XXX 匹配查询不存在 不存在。
但是,当数据库为空时,手动执行 loaddata 工作正常 就不行了。 我做了一个 dropdb,createdb 一个简单的syncdb,尝试加载数据,但失败了,同样的错误。
有什么线索吗?
Python 版本 2.6.5、Django 1.1.1
Did a dumpdata of my project, then in my new test I added it to fixtures.
from django.test import TestCase
class TestGoal(TestCase):
fixtures = ['test_data.json']
def test_goal(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.failUnlessEqual(1 + 1, 2)
When running the test I get:
Problem installing fixture
'XXX/fixtures/test_data.json':DoesNotExist: XXX matching query does
not exist.
But manually doing loaddata works fine does not when the db is empty.
I do a dropdb, createdb a simple syncdb the try loaddata and it fails, same error.
Any clue?
Python version 2.6.5, Django 1.1.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您遇到了一些外键问题。如果您的模型包含引用另一个模型的外键,但另一个模型不存在,您将收到此错误。
发生这种情况的原因有几个:如果您指向另一个应用程序中未包含在 test_data.json 转储中的模型,则会遇到麻烦。
另外,如果外键发生变化,这可能会破坏序列化——这对于自动创建的字段(例如 权限或通用关系。 Django 1.2 支持 自然键,这是一种使用模型的“自然”表示作为外键而不是可能更改的 ID 进行序列化。
Perhaps you have some foreign key troubles. If you have a model that contains a foreign key referring to another model but the other model doesn't exist, you'll get this error.
This can happen for a couple of reasons: if you are pointing to a model in another app that you didn't include in the test_data.json dump, you'll have trouble.
Also, if foreign keys change, this can break serialization -- this is especially problematic with automatically created fields like permissions or generic relations. Django 1.2 supports natural keys, which are a way to serialize using the "natural" representation of a model as a foreign key rather than an ID which might change.