我正在尝试编写简单的程序来使用在表中插入行,gorp
但在创建表时出现错误。
以下是代码:
package main
import _ "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 error
err no such table: Person
我会很感激你的帮助!