所以我必须用golang程序创建一个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()}第二个不想自己执行它,第一个是正确的创建自身,但无法创建表。Post
1 回答
繁星点点滴滴
TA贡献1803条经验 获得超3个赞
您应该在做时检查错误,因为这会指向您实际的错误。statement.Exec()
问题在于您在哪里而不是(注意中的s数)并且不使用关键字。CURRRENT_TIMESTAMP
CURRENT_TIMESTAMP
R
CURRENT
DEFAULT
ReviewID
创建表的语法记录如下:https://www.sqlite.org/lang_createtable.html
- 1 回答
- 0 关注
- 71 浏览
添加回答
举报
0/150
提交
取消