Migrations have to be applied to make changes to the database. In this lesson you’ll see how to use the management command migrate
to apply migrations.
Applying Django Migrations
00:01
Let’s look at applying migrations. You’ve seen how to create migrations, but at the moment they haven’t been applied. Applying them involves a separate command migrate
.
00:20 As you can see, aside from the migration you’ve seen created, there are a number of other migrations. These are all standard and are used when Django is first installed to create the database tables that it needs to run.
00:34
Let’s have another look at the database using dbshell
.
00:44
As you can see, there are now a number of tables present, including the one for our app, historical_data_pricehistory
. Let’s take a closer look at it using the .schema
command.
01:02
As you can see here, the fields from models.py
—"date"
, "price"
, and "volume"
—are all present in the database, along with "id"
, a primary key which is used to ensure all records in the database are unique.
01:22 What happens if you try and apply the migrations again? As you can see, Django has kept track of which migrations have been applied and won’t apply them again.
Become a Member to join the conversation.
koutsellisthemistoklis on March 4, 2020
Can you please explain a little more each of the commands you are using and make and eliminate the speed of given information? Thank you!