dongpuchao1680 2015-08-21 16:35
浏览 331
已采纳

gorp:“ auto_increment”附近:语法错误

I am trying to write simple program to insert the row in the table using the gorp but I am getting error on creating the table.

Following is the code:

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())
        }
}

I am getting following error:

table not created : near "auto_increment": syntax error
err no such table: Person

I would appreciate your help!

  • 写回答

1条回答 默认 最新

  • dongtao9095 2015-08-21 16:41
    关注

    You're using MySQL dialect with an SQLite database. Change

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

    to

    dbmap := &gorp.DbMap{Db: db, Dialect: gorp.SqliteDialect{}}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号