我正在尝试编写简单的程序来使用 将行插入表中,gorp但在创建表时出现错误。以下是代码:package mainimport _ "github.com/mattn/go-sqlite3"import "database/sql"import "fmt"import "github.com/go-gorp/gorp"func main() { type Person struct { Identi int64 Created int64 FName string LName string } db, _ := sql.Open("sqlite3", "mydb.db") dbmap := &gorp.DbMap{Db: db, Dialect: gorp.MySQLDialect{"InnoDB", "UTF8"}} _ = dbmap.AddTable(Person{}).SetKeys(true, "Identi") err := dbmap.CreateTables() if err != nil { fmt.Println("table not created : " + err.Error()) } person := &Person{ FName: "Joe", LName: "Smith", } err = dbmap.Insert(person) if err != nil { fmt.Println("err" + err.Error()) }}我收到以下错误:table not created : near "auto_increment": syntax errorerr no such table: Person我将不胜感激您的帮助!
1 回答
紫衣仙女
TA贡献1839条经验 获得超15个赞
您正在将 MySQL 方言与 SQLite 数据库一起使用。改变
dbmap := &gorp.DbMap{Db: db, Dialect: gorp.MySQLDialect{"InnoDB", "UTF8"}}
到
dbmap := &gorp.DbMap{Db: db, Dialect: gorp.SqliteDialect{}}
- 1 回答
- 0 关注
- 345 浏览
添加回答
举报
0/150
提交
取消