-
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
-
From the Docker shell, 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 type> docker 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.
Now, on a second computer, we can import that dumped_data.json
file into Django and copy over the media
dir.
We need to first copy over the media dir into the Docker container.
- From your second computer's terminal, type
> docker cp ./media makeabilitylabwebsite_website_1:/code/.
, which will copy themedia
dir into the Docker container at/code/.
- Make sure the
media
dir and subdirs have appropriate permissions. I launched an interactive shelldocker exec -it makeabilitylabwebsite_website_1 bash
and then set all media tochmod -R 777
(but probably could usechmod -R 755
) - In the interactive shell, you can also check that the contents have been copied over correctly
Finally, we can import the dumped_data.json
file:
- First, launch an interactive shell. From your second computer's terminal, type:
> docker exec -it makeabilitylabwebsite_website_1 bash
- From within this shell, type
$ python manage.py loaddata dumped_data.json
and it should work.
Here's an example:
apache@e86363656952:/code$ python manage.py loaddata dumped_data.json
Publication 'This is a test' has just been saved with PDF=/code/media/publications/Froehlich_ThisIsATest_ASSETS2021.pdf, checking to see if we should auto-generate a thumbnail
Checking for thumbnail at '/code/media/publications/images/Froehlich_ThisIsATest_ASSETS2021.jpg', otherwise will auto-generate
The thumbnail at `/code/media/publications/images/Froehlich_ThisIsATest_ASSETS2021.jpg` exists
No need to save, the thumbnail '/code/media/publications/images/Froehlich_ThisIsATest_ASSETS2021.jpg' already exists!
Publication 'This is a test' has just been saved with PDF=/code/media/publications/Froehlich_ThisIsATest_ASSETS2021.pdf, checking to see if we should auto-generate a thumbnail
Checking for thumbnail at '/code/media/publications/images/Froehlich_ThisIsATest_ASSETS2021.jpg', otherwise will auto-generate
The thumbnail at `/code/media/publications/images/Froehlich_ThisIsATest_ASSETS2021.jpg` exists
No need to save, the thumbnail '/code/media/publications/images/Froehlich_ThisIsATest_ASSETS2021.jpg' already exists!
Publication 'The Future of Global-Scale Spatial Data Collection and Analyses on Urban (in)Accessibility for People with Disabilities' has just been saved with PDF=/code/media/publications/Froehlich_TheFutureOfGlobalScaleSpatialDataCollectionAndAnalysesOnUrbanInAccessibilityForPeopleWithDisabilities_SPATIALDATASCIENCESYMPOSIUM2021.pdf, checking to see if we should auto-generate a thumbnail
Checking for thumbnail at '/code/media/publications/images/Froehlich_TheFutureOfGlobalScaleSpatialDataCollectionAndAnalysesOnUrbanInAccessibilityForPeopleWithDisabilities_SPATIALDATASCIENCESYMPOSIUM2021.jpg', otherwise will auto-generate
The thumbnail at `/code/media/publications/images/Froehlich_TheFutureOfGlobalScaleSpatialDataCollectionAndAnalysesOnUrbanInAccessibilityForPeopleWithDisabilities_SPATIALDATASCIENCESYMPOSIUM2021.jpg` exists
No need to save, the thumbnail '/code/media/publications/images/Froehlich_TheFutureOfGlobalScaleSpatialDataCollectionAndAnalysesOnUrbanInAccessibilityForPeopleWithDisabilities_SPATIALDATASCIENCESYMPOSIUM2021.jpg' already exists!
Publication 'The Future of Global-Scale Spatial Data Collection and Analyses on Urban (in)Accessibility for People with Disabilities' has just been saved with PDF=/code/media/publications/Froehlich_TheFutureOfGlobalScaleSpatialDataCollectionAndAnalysesOnUrbanInAccessibilityForPeopleWithDisabilities_SPATIALDATASCIENCESYMPOSIUM2021.pdf, checking to see if we should auto-generate a thumbnail
Checking for thumbnail at '/code/media/publications/images/Froehlich_TheFutureOfGlobalScaleSpatialDataCollectionAndAnalysesOnUrbanInAccessibilityForPeopleWithDisabilities_SPATIALDATASCIENCESYMPOSIUM2021.jpg', otherwise will auto-generate
The thumbnail at `/code/media/publications/images/Froehlich_TheFutureOfGlobalScaleSpatialDataCollectionAndAnalysesOnUrbanInAccessibilityForPeopleWithDisabilities_SPATIALDATASCIENCESYMPOSIUM2021.jpg` exists
No need to save, the thumbnail '/code/media/publications/images/Froehlich_TheFutureOfGlobalScaleSpatialDataCollectionAndAnalysesOnUrbanInAccessibilityForPeopleWithDisabilities_SPATIALDATASCIENCESYMPOSIUM2021.jpg' already exists!
Installed 189 object(s) from 1 fixture(s)