Skip to content

Importing data

Jon Froehlich edited this page Dec 20, 2021 · 19 revisions

Django makes it relatively easy to dump a database from one computer (dumpdata) and reload it on another (loaddata). This is useful and important for testing and bootstrapping your local development environment.

Because so much of the Makeability Lab website relies on artifacts (like PDF and PowerPoint files as well as thumbnails), it's not sufficient to just dump/load the database. We must also copy these files (stored in /code/media) from the exporting computer to the importing computer. I'll walk through everything below.

Dumping the data

1. Dumping the database

To dump the database data, you need to create an interactive bash shell into the Docker container and run the dumpdata command.

  1. Run the interactive shell in terminal: > docker exec -it makeabilitylabwebsite_website_1 bash

  2. Run the dumpdata command. Make sure you have admin access.

    apache@43cd75e1d80c:/code$ python manage.py dumpdata > dumped_data.json
    bash: dumped_data.json: Permission denied
    apache@43cd75e1d80c:/code$ su
    Password:
    root@43cd75e1d80c:/code# python manage.py dumpdata > dumped_data.json
    
  3. You might also have to copy the dumped_data.json file out of the Docker container and into your local filesystem. So, go back into terminal (not the Docker shell) and type docker cp makeabilitylabwebsite_website_1:/code/dumped_data.json .

  4. Now you should have a dumped_data.json file that you can copy over to your 2nd computer.

2. Copying the media directory

The second primary step is to copy the media directory from the Docker container into your local filesystem.

  1. From terminal (not the Docker shell), type > docker cp makeabilitylabwebsite_website_1:/code/media ., which should copy this media directory to your local filesystem
  2. I also zipped up this dir (because it can be huge) to transport it over to my 2nd computer for importing.
Clone this wiki locally