Create Database

Create Database File

Open a new terminal and run: sqlite3 poems.db

This will create a new, empty sqlite database. In the case of sqlite this is just a file alongside your other files for this project.

Create Database Structure

In the sqlite prompt enter:

CREATE TABLE poem (id INTEGER PRIMARY KEY, body TEXT, created_at timestamp);

Here we’re using SQL to create a table named “poem” with 3 columns:

  • id an integer and also the primary key
  • body for where we will store our poem
  • created_at for the date we created our poem

Then exit sqlite: .exit

You should now have a file named poems.db alongside your app.py file.

When we complete saving all data to the database the poem table will look something like this:

idbodycreated_at
1This is just to say I have eaten the mandarines…2020-07-22
2This is just to say I have eaten the apples…2020-07-23
3This is just to say I have eaten the kumquats…2020-07-23