Skip to content

Extended django loaddata command for uploading fixtures

License

Notifications You must be signed in to change notification settings

Friskes/django-loaddata

Repository files navigation

Extended django loaddata command for uploading fixtures

Project Status
CI/CD Latest Release
Quality Coverage
Package PyPI - Version PyPI - Support Python Versions Project PyPI - Downloads
Meta types - Mypy License - MIT code style - Ruff

Benefits of using this cli

  1. Adds the --insert_only flag to the loaddata command, which filters existing database records from the fixture and leaves only new records to insert, thereby preventing overwriting of field values (which may have been changed by the user) in existing records when loaddata is run again.
  2. Adds the --check_fields flag, which performs the same functions as the --insert_only flag, but additionally remembers the current fields of the loaded table when the fixture is loaded for the first time, so that when adding a new field to the table and restarting loaddata, only the records from the fixture for these new fields are successfully installed, the old fields will not be changed.

Install

  1. Install package

    pip install django-loaddata
  2. Add app name to INSTALLED_APPS

    INSTALLED_APPS = [
        'django_loaddata',
    ]
  3. Run django migrate

    python manage.py migrate
    

Command to run the program:

python manage.py loaddata

Contributing

We would love you to contribute to django-loaddata, pull requests are very welcome! Please see CONTRIBUTING.md for more information.