gorp: "auto_increment" 附近: 语法错误

gorp: near "auto_increment": syntax error

我正在尝试编写简单的程序以使用 gorp 在 table 中插入行,但在创建 table.

时出现错误

代码如下:

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

非常感谢您的帮助!

您正在对 SQLite 数据库使用 MySQL 方言。变化

dbmap := &gorp.DbMap{Db: db, Dialect: gorp.MySQLDialect{"InnoDB", "UTF8"}}

dbmap := &gorp.DbMap{Db: db, Dialect: gorp.SqliteDialect{}}