Automatic loading of Django hardware

I am running Django 1.7. My file tree for the project is this:

/project/app/fixtures/initial_data.json
/project/app/settings.py

      

I know I can run a python command manage.py loaddata app/fixtures/initial_data.json

that will work to populate my database, but I want to load it automatically on startup python manage.py migrate

. My settings include:

FIXTURE_DIRS = (
    os.path.join(BASE_DIR, '/app/fixtures/'),
)

      

But the app doesn't apply when the migration is in progress. What's the problem?

+3


source to share


1 answer


I'm afraid this is not your problem, because this is deprecated as of Django 1.7:

READ HERE

Automatic loading of raw data *

Deprecated since version 1.7: if the app uses migrations, there is no automatic loading of fixtures. Since migration is required for applications in Django 1.9, this behavior is deprecated. If you want to load raw data for your application, consider doing so when migrating your data.

If you create a fixture named initial_data. [xml / yaml / json], this fixture will be loaded every time migration starts. This is very handy, but be careful: remember that the data will be updated every time you run migrate. So don't use initial_data for the data youll want to edit.



If you really want this to work, you can always tweak manage.py

,

#... previous code ...
    from django.core.management import execute_from_command_line

    # add these lines here...
    if len(sys.argv) == 2 and sys.arg[1] == 'migrate':
        execute_from_command_line(['manage.py', 'loaddata'])

    execute_from_command_line(sys.argv)

      

Hope it helps.

+6


source







All Articles