coopernurse/gorp — Issue #3: Received #1064 error from MySQL server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for ...
Author: dmitrykim
Created: 2012-01-14 18:15:04+00:00
State: open

dbmap.CreateTables() returns sql error. Driver is mymysql

My code:

package robo

import(
"fmt"
"meteor"
"exp/sql"
"github.com/coopernurse/gorp"
_ "github.com/ziutek/mymysql/godrv"
)

//var db mysql.Conn
var db *sql.DB
var dbmap *gorp.DbMap

func Startup(){

db, err := sql.Open("mymysql", "dbname/user/pwd")
meteor.CheckError(err)

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

dbmap.AddTable(PersistentUser{}).SetKeys(true, "Key")

//meteor.CheckError(dbmap.DropTables())
meteor.CheckError(dbmap.CreateTables()) // <----------------- error here
}

func TestDao(){
testInsert()
}

func testInsert(){

Startup()

pu := &PersistentUser{-1,"33r",false}

for i:=0;i<10;i++{
pu.Id = fmt.Sprintf("user%d",i)
pu.PassedTraining = false;
err := dbmap.Insert(pu)
meteor.CheckError(err)
}

Shutdown()
}

func Shutdown(){
if db!=nil {
db.Close()
}

db = nil
dbmap = nil
}

and

type PersistentUser struct {
Key	int32
Id string
PassedTraining bool
}

after line meteor.CheckError(dbmap.CreateTables()) we get this:
panic: Fatal error: Received #1064 error from MySQL server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'int not null auto_increment, Id varchar(255), PassedTraining varchar(255), prima' at line 1"