简体   繁体   中英

Fixture not loaded into psql database - Django

I'm encountering a problem where I'm unable to load my fixture data into my psql database using the loaddata method. I'm not getting any errors but when I write: python manage.py loaddata whole.json it says that I have Installed 111 object(s) from 1 fixture(s) yet when I login to the psql database I see that none of the tables have any data.

Code examples

I'm working with the following code:

Settings.py

DATABASES = {

    'default': {

        'ENGINE': 'django.db.backends.postgresql_psycopg2',

        'NAME': 'db_name',

        'USER': 'user_name',

        'PASSWORD': config('DB_PASSWORD'),

        'HOST': 'localhost',

        'PORT': '5432',
    }
}

Signals.py

@receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs):
    if kwargs['raw']:
        return
    if created:
        ...

Details

I've followed every step in this article https://medium.com/djangotube/django-sqlite-to-postgresql-database-migration-e3c1f76711e1 . The only thing I did differently was to install the psycopg2-binary package. If you need any more details, code examples or clarifications you can just ask.

Does anyone know why the fixture is not loaded into my psql DB? Thank you in advance.

After investigating my fixture I quickly realized that I had accidentally made a dumpfile of my new psql db...

The reason this happened was because I got a primary key duplication error when trying to load the data the first time. This meant I had to use the dumpdata method again with the --natural-foreign and --natural-primary options. I just forgot to change my default database settings back to the initial sqlite db so instead I got a fixture of my new psql db... not my proudest moment...

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