Django: Getting Started Transcripts
Chapter: DB Migrations
Lecture: An initial migration script

Login or purchase this course to watch this video and the rest of the course contents.
0:00 To demonstrate how migration files work. I've created a new app to store music in our library.
0:07 You know the deal here, management command to create the app and add it to settings. This is the file.
0:17 It's pretty basic, a model called song with one character field for the title. With the model ready, all run make migrations.
0:38 Notice how that created the migrations directory here Let me open it up. This is a Python module directory, so it has a dunder init file.
0:50 It also has the 0001 initial script. This is created by make migrations and has data in it that dictates the structure of the table.
1:00 Let's take a look at it. You can see a couple of different data structures here, all of which are inside of the migration class.
1:11 First, it has an attribute that indicates that this is the initial migration. Seond is a list of dependencies. If there was anything in here,
1:19 these scripts would be run before this one in the migration process. Third is a list of operations.
1:27 The operation here represents the creating of the table in the database. The fields list has all the information
1:33 the migration command needs to create a table that maps to the current version of the song model. Although I only defined a title column.
1:41 Every Django model has a big integer primary key for its ID. So there are two fields here. Ok, let's migrate this.

Talk Python's Mastodon Michael Kennedy's Mastodon