#100DaysOfWeb in Python Transcripts
Chapter: Days 57-60: Flask Login
Lecture: Create the database!

Login or purchase this course to watch this video and the rest of the course contents.
0:00 And now, for the fun part
0:01 of actually creating our database.
0:03 We've defined it, we've defined the data
0:06 that's going to go in it, which was that user class.
0:08 And now, we create it.
0:10 When you're working with databases
0:12 in this sort of an environment
0:15 you don't actually manage them from
0:17 within your primary script as you may have done before
0:21 with SQLite3 in your Flask apps or anything like that.
0:26 No, in this instance, we actually manage it
0:29 on the command line or within the Python shell.
0:32 Specifically here, we're going to pop into the Python shell
0:35 and we're going to actually create our database there
0:39 fro the very first time.
0:40 Now, it doesn't matter where you do this from.
0:43 If you do it within this current folder, the Project Awesome
0:46 within this Flask view, it will not be able to create itself
0:51 because it can't call all of the dependencies
0:54 and all of the files.
0:56 The pathing just isn't there.
0:58 So we need to actually run it from
1:01 our Flask.login folder up here, the parent folder.
1:05 And by doing it from here, it will be able to talk
1:08 to the init.py file and create our database
1:13 call on the right libraries and what-not.
1:16 So launch your Python shell from your parent folder.
1:19 Now, this is going to seem really simple
1:21 and it's because it it.
1:23 We're actually just going to import that database object
1:27 from that init.py file from our project.
1:32 And when we import this, we run create_all against it
1:37 and what this will do is it will create our database
1:41 based on the models that we defined
1:43 in the models.py file.
1:46 So let's import that.
1:48 So from Project Awesome, import db.
1:54 And just ignore that message, this is something
1:56 you can look into later.
1:57 It doesn't really affect us now, to be honest.
2:00 And we can now run dp.create underscore all
2:05 and that will create our database with all the columns
2:08 and everything that we need.
2:10 So exit out of the shell.
2:12 You'll see there's nothing here
2:14 so pop into Project Awesome
2:17 and there is our site users.db file.
2:21 What I'd like you to do now is open up
2:23 your SQLite database browser that we installed
2:26 in the last video and then take a look at that file.
2:31 So open that database in your program
2:34 and you should see something like this.
2:36 There we go.
2:37 We have a table, we have a single table
2:40 and it is called user.
2:43 Now, this is based on us creating that user model file.
2:48 So within our models file, we created a user class
2:52 and we ended up with a user table here.
2:55 If we click on the browse data tab
2:58 we then have those three columns that we defined.
3:02 We have ID, we have username, and we have password.
3:06 Now when we use our actual Flask app, we will be able to see
3:10 all of these get populated as data
3:13 is being pumped in from the web