8π
I Am not sure if this fixes your problem, but on this site:
https://code.djangoproject.com/wiki/Fixtures
I found an interesting remark:
you see that Django searches for appnames/fixtures and
settings.FIXTURE_DIRS and loads the first match. So if you use names
like testdata.json for your fixtures you must make sure that no other
active application uses a fixture with the same name. If not, you can
never be sure what fixtures you actually load. Therefore it is
suggested that you prefix your fixtures with the application names,
e.g. myapp/fixtures/myapp_testdata.json .
Applying this (renaming the fixtures with appname as prefix in the filename), solved my problem (I had the same issue as described here)
37π
Import the TestCase from django.test
:
from django.test import TestCase
class test_something(TestCase):
fixtures = ['one.json', 'two.json']
...
- Not:
import unittest
- Not:
import django.utils.unittest
- But:
import django.test
Thatβs a day of frustration right there.
Stop complaining β itβs in the docs :-/
- [Django]-Django trans and url tags
- [Django]-Django: ordering numerical value with order_by
- [Django]-Django {% static 'path' %} in javascript file
5π
Check if the fixture is really in the right place. From the docs:
Django will search in three locations
for fixtures:
- In the fixtures directory of every installed application
- In any directory named in the FIXTURE_DIRS setting
In the literal path named by the fixture
- [Django]-Django: Integrity error UNIQUE constraint failed: user_profile.user_id
- [Django]-Django flush vs sqlclear & syncdb
- [Django]-How to set NULL for IntegerField instead of setting 0?
2π
One thing to note, when creating the FIXTURE_DIRS constant in your settings file, be sure to leave out the leading β/β if you have a general fixtures directory off of the root of your project.
Ex:
β/actual/path/to/my/app/fixtures/β
Now, in the settings.py file:
Will NOT work:
FIXTURE_DIRS = β/fixtures/β
Will work:
FIXTURE_DIRS = βfixtures/β
Itβs possible this depends on how your other routes are configured, but it was a gotcha that had me scratching my head for a little while. Hope this is useful. Cheers.
- [Django]-Filtering ListAPIView in django-rest-framework
- [Django]-What is "swappable" in model meta for?
- [Django]-Django static files versioning
2π
A simple mistake I made was adding a custom setUpClass()
and forgetting to include super().setUpClass()
with it (which of course, is where Djangoβs logic for loading fixtures lives)
- [Django]-Django: OperationalError No Such Table
- [Django]-ImportError: cannot import name 'url' from 'django.conf.urls' after upgrading to Django 4.0
- [Django]-What is the equivalent of "none" in django templates?
0π
For me: required TestCase rather than SimpleTestCase! Still donβt see the data in postgres after import pdb; pdb.set_trace() but the data is there as reported by my API Call tests..
- [Django]-Auto-reloading of code changes with Django development in Docker with Gunicorn
- [Django]-Django reverse() for JavaScript
- [Django]-How can I set default value in serializers?