简体   繁体   中英

Django and PostgreSQL “No Fixtures Found”

I've been trying to use PostrgeSQL with my Django apps but I get the following error before (right after starting the project when I only have the following files: __init__.py , manage.py , settings.pyc , urls.pyc , __init__.pyc , settings.py , urls.py ) and after I've added models:

python manage.py syncdb
Creating tables ...
Installing custom SQL ...
Installing indexes ...
No fixtures found.

I'm not even trying to load fixtures. Psycopg2 is installed. This is the database section of my settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'myapp_development',                     
        # Or path to database file if using sqlite3.
        'USER': 'foo',                      # Not used with sqlite3.
        'PASSWORD': 'password',                  # Not used with sqlite3.
        'HOST': '',       
        # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                    
        # Set to empty string for default. Not used with sqlite3.
    }
}

This means that Django had not found any fixtures. This is a standard message if there are no fixtures.

Fixture is a file of the next format (using to create real objects in a database by an existing model):

[
  {
    "model": "myapp.person",
    "pk": 1,
    "fields": {
      "first_name": "John",
      "last_name": "Lennon"
    }
  },
  {
    "model": "myapp.person",
    "pk": 2,
    "fields": {
      "first_name": "Paul",
      "last_name": "McCartney"
    }
  }
]

See more for details: http://docs.djangoproject.com/en/dev/howto/initial-data/

Did you set the FIXTURE_DIRS setting value in your settings.py ?

See here for documentation.

When you run

manage.py syncdb

django try to load initial data for apps in you project. By default that data loaded from app-dir\\fixtures\\initial_data.[xml/yaml/json] files So when file does not exist you see:

No fixtures found

Lean more on django official page :

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM