Next we're going to create a django migration file for our models that we've
added to the project
The way that django manages the database is it creates
what's called a migration file that stores all of the steps required to make
our database match our django models
so every time you change a model or add
additional models to your project you need to create a new migration file the
migration file will contain the steps required to modify the database to match
our updated models so for example if you add a new model to our project then we
need to be able to create a new table in the database and the way that django
does this is it uses what's called migrations you can create django
migrations using the django command-line tool so open up the
terminal or the git bash window and type cd then change to our workspace and our
project location and then do vagrant ssh to connect to a vagrant server
Once you're on the server type CD forward slash vagrant to switch to the vagrant
directory and then type source tilde forward slash env slash bin slash
activate to activate our virtual environment
Once you're on the virtual
environment we can use the Python or the Django manage dot py file to create our
migrations for our projects so type Python manage dot py make migrations and
then the name of the app we want to make the migrations for so we're going to make
it for the profiles underscore API app hit enter and this should create a new
migration file in our project for our user profile model so you can see here
that it has created a new file 0 0 0 1 initial and this work contains all the
steps required to create our models so migrations dot create model
you shouldn't usually need to modify or view this file but it's good
to know how it works just in case you ever do
Okay now that we've created our
migration we can go ahead and run our migration which will make all the
changes required to set up our database for our Django project so type Python
manage dot py migrate this will run all the migrations in our project so when
you hit enter you can see that it does a bunch of steps here and it says okay
next to each one so it will go through our entire Django project and create all
the required models or all the required tables in the database for any of our
models and any of the dependencies that we have so for example the Django auth
system that's out of the box the Django admin it creates tables in the
database for all of these projects
Okay so that's how you create and manage
changes let's go ahead and commit our changes to github so open a new terminal
window and type git add dot and then git commit
- am and then the commit string or the commit message which is added custom
user profile model manager and migrations
Hit enter and do git push
origin to push our changes to github