所以我必須用golang程序創(chuàng)建一個(gè)sqlite表,所以我這樣做了:package mainimport ( "database/sql" "log" _ "github.com/mattn/go-sqlite3")func main() { database, err := sql.Open("sqlite3", "./ProjetForum.db") if err != nil { log.Fatal(err) } defer database.Close() statement, err := database.Prepare("CREATE TABLE IF NOT EXISTS Users (UserID integer NOT NULL primary key, Pseudo text NOT NULL , Email text NOT NULL , Rank integer NOT NULL DEFAULT 0, Phone text , Description text , ArrivingDate integer NOT NULL DEFAULT CURRENT_TIMESTAMP , Key text NOT NULL , Verified integer NOT NULL DEFAULT 0 , Banned integer NOT NULL DEFAULT 0 , Deleted integer NOT NULL DEFAULT 0 , Points integer NOT NULL DEFAULT 0 , Staff integer NOT NULL DEFAULT 0 , Image blob )") if err != nil { log.Fatal(err) } statement.Exec() statement, erro := database.Prepare("CREATE TABLE IF NOT EXISTS Posts (PostID integer NOT NULL primary key , Title text NOT NULL , Description text NOT NULL , PublishDate integer NOT NULL DEFAULT CURRENT_TIMESTAMP, Closed integer NOT NULL DEFAULT 0 , Verified integer NOT NULL DEFAULT 0 , ReviewID integer NOT NULL DEFAULT 0 , Deleted text NOT NULL , ToReview integer NOT NULL DEFAULT 0 , Points integer NOT NULL DEFAULT 0 , Likes integer NOT NULL DEFAULT 0 , Dislikes integer NOT NULL DEFAULT 0 , UserID integer NOT NULL DEFAULT 0, FOREIGN KEY (`UserID`) references Users(`UserID`)) ") if erro != nil { log.Fatal(erro) } statement.Exec()}第二個(gè)不想自己執(zhí)行它,第一個(gè)是正確的創(chuàng)建自身,但無(wú)法創(chuàng)建表。Post
1 回答

繁星點(diǎn)點(diǎn)滴滴
TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超3個(gè)贊
您應(yīng)該在做時(shí)檢查錯(cuò)誤,因?yàn)檫@會(huì)指向您實(shí)際的錯(cuò)誤。statement.Exec()
問(wèn)題在于您在哪里而不是(注意中的s數(shù))并且不使用關(guān)鍵字。CURRRENT_TIMESTAMP
CURRENT_TIMESTAMP
R
CURRENT
DEFAULT
ReviewID
創(chuàng)建表的語(yǔ)法記錄如下:https://www.sqlite.org/lang_createtable.html
- 1 回答
- 0 關(guān)注
- 90 瀏覽
添加回答
舉報(bào)
0/150
提交
取消