2

I'm using Django 3.2 and Python 3.9. I have this project directory setup

+ cbapp
    - manage.py
    - settings.py
    + models
        - __init__.py
        - crypto_currency.py

In my settings.py file, I have

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'cbapp',
]

I want to dump some data to a fixtures file, so I tried

$ python3 manage.py dumpdata cbapp.models.crypto_currency  > ./cbapp/fixtures/crypto_currency.json
CommandError: No installed app with label 'cbapp.models.crypto_currency'.

What's the proper way to reference my model to dump data?

Dave
  • 15,639
  • 133
  • 442
  • 830

1 Answers1

2

Firstly in cbapp/models/__init__.py I think you have to import all models from crypto_currency.py. Like so: from .crypto_currency import *

Then you should be able to use (Replace CryptoModel with the name of your model):

python3 manage.py dumpdata cbapp.CryptoModel > ./cbapp/fixtures/crypto_currency.json
Felix Eklöf
  • 3,253
  • 2
  • 10
  • 27
  • Thanks, gave this is a try but get the same error. – Dave Nov 05 '21 at 17:18
  • Maybe it's because you have your models folder inside the same folder as `manage.py`, try running `py manage.py startapp [appname]` and add it in settings.py in `INSTALLED_APPS`. Then move your models folder to that new app – Felix Eklöf Nov 05 '21 at 22:35