From the course: Building RESTful APIs with Flask
Unlock the full course today
Join today to access over 24,300 courses taught by industry experts.
Seeding the database with the Flask CLI
From the course: Building RESTful APIs with Flask
Seeding the database with the Flask CLI
- [Instructor] We have our database structure in our code, but we need a way to manage our database file. Typically, what you see is a script that creates the database from class definitions, a script that destroys the database so you can start from scratch for testing, and a seed script that enters some initial data for you to work with. With the 1.0 release of Flask, we got a new tool, the Flask command line interface, or CLI. The CLI allows you to run arbitrary commands against your app. This is actually how we're starting our dev web server right now, but PyCharm has handled all those details for us. We'll start by adding a few commands. I'm going to scroll up a little bit, and I'm going to put my CLI commands right below where I initialized the database. So we're going to write three scripts. The first one is going to create the database, the second one is going to destroy it, and the third one is going to seed it. So for the creation, let's create a function called db_create for…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Adding an ORM (SQLAlchemy)3m 23s
-
(Locked)
Setting up SQLAlchemy4m 2s
-
(Locked)
Creating the ORM model classes6m 12s
-
(Locked)
Seeding the database with the Flask CLI8m 47s
-
(Locked)
Viewing the database in DB Browser for SQLite5m 8s
-
(Locked)
Retrieving a list of planets from the database6m 20s
-
(Locked)
Serializing SQLAlchemy results with Marshmallow8m 44s
-
-
-
-