I've a very simple app and I've created a fixture. A folder named as fixtures and a file named as initial_data.json. Following is the code I've in my initial_data.json file:
[
{
"model": "myapp.model_in_lower_case",
"pk": 1,
"fields": {
"title": "my Title",
"description": "Description goes here..."
}
}
]
But when I run the syncdb command, it says zero fixtures found and the data is not being saved. What's missing?
Make sure you are using manage.py /dumpdata to export the fixture.
save the fixuture under your app fixtures directory not your project directory.
name it initial_data.json and it should work for you.
when the json file does not fit to your database or is invalid, manage.py will throw an exception. I am positive that currently you didnt put the json file in the right place.
Related
I am trying to launch a Django project and am unable to do so because it seems my local environment is disconnected from my .env file in the root directory. I've never had this problem before and assume there is an easy fix but I can't seem to figure it out. When I run basic commands like runserver I get the following error:
RATE_LIMIT_DURATION = int(os.environ.get("RATE_LIMIT_DURATION"))
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
In my .env file, I have defined the variable as:
RATE_LIMIT_DURATION = 10
I have already confirmed that my database is setup and I am pretty sure my settings are in good shape otherwise.
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": os.environ.get("DB_NAME"),
"USER": os.environ.get("DB_USER"),
"PASSWORD": os.environ.get("DB_PASSWORD"),
"HOST": "localhost",
"PORT": 8000,
}
}
When I want to include .env to my django project I just use load_dotenv from dotenv python library.
So basically in settings.py I put:
from dotenv import load_dotenv
load_dotenv()
I am able to load 1 fixture file into the database, but not the 2nd file. I run the command python manage.py loaddata fixture.json, and I get the error. I'm not sure how to solve this serialization error, any insights appreciated.
The error:
for obj in objects:
File "/Users/ayunas/.local/share/virtualenvs/CS24-BW-MUD-lJVJyZQx/lib/python3.7/site-packages/django/core/serializers/json.py", line 73, in Deserializer
raise DeserializationError() from exc
django.core.serializers.base.DeserializationError: Problem installing fixture '/Users/ayunas/Documents/lambda/CS24-BW-MUD/tower_app/fixtures/test_fixture.json':
Here is how the fixture file looks like:
[
{
"model": "tower_app.item",
"pk": 1,
"fields": {
"item_name": "Black Stone",
"description": "a white stone from Paradise, blackened by the sins of mankind.",
"strength": 10,
"item_type": "weapon",
"playerID" : null,
"roomID" : 4
}
}
]
While working a migration of an older Django project I ran into this error after running:
python manage.py check
cms.UserSettings.language: (fields.E005) 'choices' must be an iterable containing (actual value, human readable name) tuples.
Has anyone run into this issue? Unfortunately I have to wait until I am not on the corp network before I can ask the IRC channels.
http://docs.django-cms.org/en/latest/reference/configuration.html#cms-languages
It turns out I missed this important setting in my settings.py file:
CMS_LANGUAGES = {
'default': {
'fallbacks': ['en',],
'redirect_on_fallback':True,
'public': True,
'hide_untranslated': False,
}
}
Thanks to brianpck for a point in the right direction though.
I have a Django 1.5.5 project that uses South 0.8.2. Everything works great -- including migration using South. When I attempt to upgrade this project to South 0.8.3, I get the following error when I run python manage.py migrate:
(VBEZ)vagrant#vagrant-ubuntu-precise-64:/vagrant$ python manage.py migrate
Running migrations for django_mailbox:
- Nothing to migrate.
- Loading initial data for django_mailbox.
Installed 3 object(s) from 1 fixture(s)
Running migrations for djcelery:
- Nothing to migrate.
- Loading initial data for djcelery.
DeserializationError: Problem installing fixture 'initial_data.json': Invalid model identifier: 'sites.site'
What has happened?
Here is my initial_data.json file:
[
{
"pk": 1,
"model": "sites.site",
"fields": {
"domain": "0.0.0.0:5000",
"name": "Project (Development)"
}
},
{
"pk": 2,
"model": "sites.site",
"fields": {
"domain": "project-staging.example.com",
"name": "Project (Staging)"
}
},
{
"pk": 3,
"model": "sites.site",
"fields": {
"domain": "project.example.com",
"name": "Project"
}
}
]
Here is what a successful migration using South 0.8.2 looks like:
Running migrations for django_mailbox:
- Nothing to migrate.
- Loading initial data for django_mailbox.
Installed 3 object(s) from 1 fixture(s)
Running migrations for djcelery:
- Nothing to migrate.
- Loading initial data for djcelery.
Installed 3 object(s) from 1 fixture(s)
Running migrations for taggit:
- Nothing to migrate.
- Loading initial data for taggit.
Installed 3 object(s) from 1 fixture(s)
Running migrations for eee_core:
- Nothing to migrate.
- Loading initial data for eee_core.
Installed 3 object(s) from 1 fixture(s)
Running migrations for core:
- Nothing to migrate.
- Loading initial data for core.
Installed 3 object(s) from 1 fixture(s)
Things I have looked at/tried:
django-contrib-sites is in my `INSTALLED_APPS'
Migration works fine if the initial_data.json file is removed.
If I run migrations individually, they run fine. Example python manage.py migrate myapp.
I have submitted a ticket: http://south.aeracode.org/ticket/1324
Thanks.
Looks like this a known bug in South 0.8.3: http://south.aeracode.org/ticket/1320. Fix is expected in a week or so.
Update: South 0.8.4 fixes this bug.
I've created a json fixture, and put it in my myapp/fixtures/. I've added myapp/fixtures to settings.FIXTURE_DIRS.
Here's the output of my attempt to load the fixture:
jeff#jeff-linux:~/myapp$ ./manage.py loaddata --verbosity=2 default.json
Loading 'default' fixtures...
[...truncated checking default paths and installed apps/fixtures...]
Checking '/home/jeff/myapp/fixtures/' for fixtures...
Trying '/home/jeff/myapp/fixtures/' for default.json fixture 'default'...
No json fixture 'default' in '/home/jeff/myapp/fixtures/'.
Trying '/home/jeff/myapp/fixtures/' for default.json.gz fixture 'default'...
No json fixture 'default' in '/home/jeff/myapp/fixtures/'.
Trying '/home/jeff/myapp/fixtures/' for default.json.zip fixture 'default'...
No json fixture 'default' in '/home/jeff/myapp/fixtures/'.
Trying '/home/jeff/myapp/fixtures/' for default.json.bz2 fixture 'default'...
No json fixture 'default' in '/home/jeff/myapp/fixtures/'.
Checking absolute path for fixtures...
Trying absolute path for default.json fixture 'default'...
No json fixture 'default' in absolute path.
Trying absolute path for default.json.gz fixture 'default'...
No json fixture 'default' in absolute path.
Trying absolute path for default.json.zip fixture 'default'...
No json fixture 'default' in absolute path.
Trying absolute path for default.json.bz2 fixture 'default'...
No json fixture 'default' in absolute path.
No fixtures found.
jeff#jeff-linux:~/myapp$ ls fixtures/
defaults.json moneytrail.json
here's what's in default.json:
[
{
"pk": 1,
"model": "myapp.feature",
"fields": {
"default_feature": "0.25"
}
}
]
Am I missing something obvious here? I've tried the FIXTURE_DIRS as both fixtures and fixtures/ same results.
Thanks.
Your file: defaults.json
Your command line argument: default.json
Look closely.