-
Notifications
You must be signed in to change notification settings - Fork 65
Importing data
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.
To dump the database data, you need to create an interactive bash shell into the Docker container and run the dumpdata
command.
-
Run the interactive shell in terminal:
> docker exec -it makeabilitylabwebsite_website_1 bash
-
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
-
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 typedocker cp makeabilitylabwebsite_website_1:/code/dumped_data.json .
-
Now you should have a
dumped_data.json
file that you can copy over to your 2nd computer.
The second primary step is to copy the media directory from the Docker container into your local filesystem.
- From terminal (not the Docker shell), type
> docker cp makeabilitylabwebsite_website_1:/code/media .
, which should copy thismedia
directory to your local filesystem - I also zipped up this dir (because it can be huge) to transport it over to my 2nd computer for importing.