2016-04-24 135 views
2

我試圖插入值到我的表,但得到一個沒有這樣的列錯誤。我在尋找,看到在大多數情況下,這是因爲他們錯過了引號,但我似乎擁有它們。任何人都可以將我指向正確的方向嗎?在sqlite3沒有這樣的列錯誤

CREATE TABLE students (
id INTEGER PRIMARY KEY, 
first_name VARCHAR(255), 
last_name VARCHAR(255), 
grade INT, 
passing BOOLEAN, 
teacher_id INT, 
FOREIGN KEY (teacher_id) REFERENCES teachers(id) 
); 

INSERT INTO students (first_name, last_name, grade, passing, teacher_id) 
VALUES (‘Ted’, ‘Mosby’, 84, true, 2); 

Error: no such column: ‘Ted’

回答

2

使用'1代替true

SQLite does not have a separate Boolean storage class. Instead, Boolean values are stored as integers 0 (false) and 1 (true).

INSERT INTO students (first_name, last_name, grade, passing, teacher_id) 
VALUES ('Ted', 'Mosby', 84, 1, 2); 

SqlFiddleDemo

輸出:

╔═════╦═════════════╦════════════╦════════╦══════════╦════════════╗ 
║ id ║ first_name ║ last_name ║ grade ║ passing ║ teacher_id ║ 
╠═════╬═════════════╬════════════╬════════╬══════════╬════════════╣ 
║ 1 ║ Ted   ║ Mosby  ║ 84 ║  1 ║   2 ║ 
╚═════╩═════════════╩════════════╩════════╩══════════╩════════════╝ 
+1

該死的,難怪。我的mac是autocorrecting。非常感謝! –

相關問題