Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Creating Django Migrations

Give Feedback

This lesson will show you what steps to take to before making migrations, You’ll learn how to create a new Django project, create models and how to make migrations from models.

00:01 Let’s have a look at creating migrations. To create migrations, you’ll need a Django project. Let’s create one now. I’ve made a new directory and I’m installing Django into a new virtual environment.

00:23 Now the virtual environment will be activated.

00:32 And then I’m going to clear the screen to make it a little easier to see what’s going on. So next up, creating a new project with django-admin.

00:48 You can see the contents of the directory there, and you can see manage.py, which we’ll be making a lot of use of throughout this tutorial.

01:05 And there using the tree command, you can see the structure of the files and directories that we have so far. You can notice that at the moment our migrations/ folder inside historical_data/ is empty, so next up it will be time to create the model that we be working with and install the historical_data app into Django.

01:37 First up, you’re adding 'historical_data' to the INSTALLED_APPS in Django’s settings.py file. One thing I’ve gotten in the habit of doing is putting a comment to separate out third-party apps and local ones I’ve been working on because later on when things get a little more complicated, it can make it clearer to see what’s happening.

02:04 It’s good practice to put a comma (,) after the last item on any list that you make, because then if you do extend it in the future, you won’t generate any errors.

02:15 Next, creation of the model in the historical_data/models.py file.

02:27 There you can see the basic model to keep track of Bitcoin prices with three fields in there. We have date, that’s a datetime field. We have price as a decimal field.

02:41 We have volume as an integer field. Now that the model has been created, the next thing you need to do is to make a migration for it, and that can be done using manage.py makemigrations.

02:59 You can optionally add the name of the app. This will make migrations solely for the app in question and can simplify debugging later on. Now the migration has been done and if we look again at the structure of our files and directories, we can see that our migrations/ folder contains the migration.

03:25 The eagle-eyed amongst you may also have noticed that a database file has been created. Let’s take a look at that now using manage.py dbshell.

03:39 The SQLite instruction to look at the tables is simply .tables, and we can see at the moment there are no tables. .quit puts us back at the prompt.

Become a Member to join the conversation.