WEBVTT
Kind: captions
Language: en

00:00:00.030 --> 00:00:05.130
Next we're going to create a django
migration file for our models that we've

00:00:05.130 --> 00:00:07.760
added to the project

00:00:07.760 --> 00:00:11.190
The way that django
manages the database is it creates

00:00:11.190 --> 00:00:16.289
what's called a migration file that
stores all of the steps required to make

00:00:16.289 --> 00:00:19.800
our database match our django models

00:00:19.800 --> 00:00:22.410
so  every time you change a model or add

00:00:22.410 --> 00:00:28.080
additional models to your project you
need to create a new migration file the

00:00:28.080 --> 00:00:32.640
migration file will contain the steps
required to modify the database to match

00:00:32.640 --> 00:00:39.960
our updated models so for example if you
add a new model to our project then we

00:00:39.960 --> 00:00:45.090
need to be able to create a new table in
the database and the way that django

00:00:45.090 --> 00:00:49.890
does this is it uses what's called
migrations you can create django

00:00:49.890 --> 00:00:54.210
migrations using the  django
command-line tool so open up the

00:00:54.210 --> 00:01:00.930
terminal or the git bash window and type
cd then change to our workspace and our

00:01:00.930 --> 00:01:08.560
project location and then do vagrant ssh
to connect to a vagrant server

00:01:08.560 --> 00:01:12.900
Once you're on the server type CD forward
slash vagrant to switch to the vagrant

00:01:12.900 --> 00:01:21.080
directory and then type source tilde
forward slash env slash bin slash

00:01:21.080 --> 00:01:25.500
activate to activate our virtual
environment

00:01:25.500 --> 00:01:26.610
Once you're on the virtual

00:01:26.610 --> 00:01:32.130
environment we can use the Python or the
Django manage dot py file to create our

00:01:32.130 --> 00:01:40.720
migrations for our projects so type
Python manage dot py make migrations and

00:01:40.720 --> 00:01:45.840
then the name of the app we want to make
the migrations for so we're going to make

00:01:45.840 --> 00:01:52.759
it for the profiles underscore API app
hit enter and this should create a new

00:01:52.759 --> 00:01:59.219
migration file in our project for our
user profile model so you can see here

00:01:59.219 --> 00:02:06.930
that it has created a new file 0 0 0 1
initial and this work contains all the

00:02:06.930 --> 00:02:10.800
steps required to create our models so
migrations dot create model

00:02:10.800 --> 00:02:15.540
you shouldn't usually need to modify
or view this file but it's  good

00:02:15.540 --> 00:02:20.360
to know how it works just in case you
ever do

00:02:20.360 --> 00:02:22.439
Okay now that we've created our

00:02:22.439 --> 00:02:27.150
migration we can go ahead and run our
migration which will make all the

00:02:27.150 --> 00:02:34.280
changes required to set up our database
for our Django project so type Python

00:02:34.280 --> 00:02:41.819
manage dot py migrate this will run all
the migrations in our project so when

00:02:41.819 --> 00:02:46.230
you hit enter you can see that it does a
bunch of steps here and it says okay

00:02:46.230 --> 00:02:50.609
next to each one so it will go through
our entire Django project and create all

00:02:50.609 --> 00:02:55.739
the required models or all the required
tables in the database for any of our

00:02:55.739 --> 00:03:01.170
models and any of the dependencies that
we have so for example the Django auth

00:03:01.170 --> 00:03:05.909
system that's out of the box the Django
admin it creates tables in the

00:03:05.909 --> 00:03:08.980
database for all of these projects

00:03:08.980 --> 00:03:11.129
Okay so that's how you create and manage

00:03:11.129 --> 00:03:16.290
changes let's go ahead and commit our
changes to github so open a new terminal

00:03:16.290 --> 00:03:21.480
window and type git add dot and then git
commit

00:03:21.480 --> 00:03:28.169
- am and then the commit string or the
commit message which is added custom

00:03:28.169 --> 00:03:35.520
user profile model manager and
migrations

00:03:35.520 --> 00:03:37.590
Hit enter and do git push

00:03:37.590 --> 00:03:43.010
origin to push our changes to github

