Django: Getting Started Transcripts
Chapter: Django ORM and Databases
Lecture: Exporting data with 'dumpdata'

Login or purchase this course to watch this video and the rest of the course contents.
0:00 I'm back in my bash shell and I want to get some data out of my database. I do that by running the dump data management command.
0:08 This command requires at least one argument. The name of the app whose data is being dumped. That's a little squishy and hard to read
0:19 but it's a list of dictionaries in JSON format. Each dictionary specifies the model being serialized the PK or primary key and a
0:28 sub dictionary containing the model's fields. Using a little command line trickery.
0:33 I can redirect the result of that data dump into a file named catalog.JSON Now I'm going to delete the database
0:45 if you're a Windows person meet one of the most dangerous commands in UNIX. rm, short for remove it deletes files. It deletes directories.
0:54 If you've got the right permissions it will delete your entire operating system. Go ask a UNIX graveyard.
0:59 I've never met one who didn't have a how I messed up by using rm story With the database gone, I'm now starting from scratch.
1:07 Let me perform the migration. Remember that the data on what was migrated was also
1:16 stored in the database, so destroying that database, destroys that information.
1:21 Running migrate, creates a new database with all those tables you saw before in sqlite.
1:27 Let me go back into the Django shell, import, run a query and hopefully that's not a surprise.
1:38 Back out to the shell and now I can take the serialized data created by the dump data command and load it into the new database
1:46 using the load data command. The command takes the name of one or more files containing data
1:55 as arguments and then tells you how many objects were loaded from how many fixture files.
2:02 Back into Django is ripple importing, querying, and isn't that beautiful? Everything is back the way it was?


Talk Python's Mastodon Michael Kennedy's Mastodon