开发者

Django: text fixture fails to load

开发者 https://www.devze.com 2022-12-29 01:41 出处:网络
Did a dumpdata of my project, then in my new test I added it to fixtures. from django.test import TestCa开发者_JAVA技巧se

Did a dumpdata of my project, then in my new test I added it to fixtures.

from django.test import TestCa开发者_JAVA技巧se

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消