django 1.7: Problems loading the initial fixture of the test

705 views Asked by At

Environment:

Django version: 1.7.1
Nose version: 1.3.4
django-nose version: 1.2

I have two apps:
dog and human

The model has:

class Dog(models.Model):
    human = models.ForeignKey('humans.Human', null=False)

    def askFood(human):
       ...

human

and in the model there is a function like in the example attributes of human, like

name = models.CharField(_('Name'), null=False, max_length=120)

The two apps are listed the INSTALLED_APPS in the settings file.

The FIXURE_DIRS is as follows:

FIXTURE_DIRS = (
    os.path.join(os.path.dirname(__file__), '../**/tests'),
)

The tests are in the tests folder of the dog app.

I have a test in the dog app to test the askFood funcion, and I have a JSON fixture(initial_data) with a human.

[
    {
        "pk": 1,
        "model": "human.Human",
        "fields": {
            "name": "Test"
        }
    },
]

The test is:

class DogFixtureTestCase(TestCase):
    fixtures = ['./initial_data.json']

class TestFixtureDog(DogFixtureTestCase):
    def test_ask_food(self):
        ...

I execute the command to test:

python manage.py test dog

There is an error:

no such table: dog_dog

Apparently it is not syncing all the apps, it is creating the tables only of the dog, when the fixture runs it cannot find the human table. How can I force the tests to create the model to all apps?

Thanks in advance for the help :)

[EDIT]

I changed the title and posted an answer to maybe help someone with the same problem.

The problem is not that the sync doesn't create all the tables, the error message that is misleading. The problem is with the initial data fixture that is not supported in the django 1.7 anymore.

1

There are 1 answers

0
AlexVanAxe On BEST ANSWER

Ok, I'm going to answer my question :)

I found a bug report in the bug tracker of django:

The problem is not loading the fixtures, but only the initial data.

Note that ​initial data isn't supported if an application has migrations. It may be worth throwing a more informative error message though.

So apparently there are three options:

  • Migrate the fixtures to the new "Data Migrations".
  • Load the data programmatically using the setUp of the unit tests.
  • Don't load the inital_data.json automatically (remove the initial_data.json) from the "path" of the fixtures. The problem is loading the initial data and not the fixtures.