天天看點

Flask學習筆記(2 - 1)步驟 1: 資料庫模式(關鍵詞:資料庫模式)

步驟 1: 資料庫模式

首先我們要建立資料庫模式。對于這個應用來說,一張表就足夠了,而且隻需支援 SQLite,是以會很簡單。隻需要把下面的内容放進一個名為 schema.sql 的檔案,放在剛才建立的 flaskr 檔案夾中:

drop table if exists entries;
create table entries (
  id integer primary key autoincrement,
  title string not null,
  text string not null
);
           

這個模式包含一個名為 entries 的表,該表中的每行都包含一個 id 、一個 title 和一個 text 。 id 是一個自增的整數,也是主鍵;其餘的兩個是字元串,且不允許為空。

閱讀 步驟 2: 應用設定代碼 以繼續。

參考文獻:

  1. Flask中文文檔 - 教程 - 步驟 1: 資料庫模式;
  2. Flask英文文檔 - Tutorial - Step 1: Database Schema。

繼續閱讀