V
V
v- death2015-08-17 12:40:23
MySQL
v- death, 2015-08-17 12:40:23

Why is mysql returning an error?

Here is the code

type User struct {
    UserID         int    `sql:"AUTO_INCREMENT"`
    UserLogin      string `sql:"type:varchar(50)"`
    UserPass       string `sql:"type:varchar(200)"`
    UserSaltInt    string `sql:"type:bigint"`
    UserSaltString string `sql:"type:text"`
  }

  db, err := gorm.Open("mysql", "root:[email protected]/generais?charset=utf8&parseTime=True&loc=Local")
  if err != nil {
    log.Fatal(err)
  }
  db.DB()
  db.DB().Ping()
  db.DB().SetMaxIdleConns(10)
  db.DB().SetMaxOpenConns(100)
  db.SingularTable(true)

  db.CreateTable(&User{})
  db.Set("gorm:table_options", "ENGINE=InnoDB").CreateTable(&User{})

Returns an error
(Error 1075: Incorrect table definition; there can be only one auto column and it must be defined as a key) 
[2015-08-17 12:37:23]  

(Error 1075: Incorrect table definition; there can be only one auto column and it must be defined as a key) 
[2015-08-17 12:37:23]

What did I do wrong? Thanks in advance.
https://github.com/jinzhu/gorm
If you comment out the line with auto increment, it will create a table and write to the log
(Error 1050: Table 'user' already exists) 
[2015-08-17 12:42:55]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Fateev, 2015-08-17
@vGrabko99

PRIMARY KEY not specified

O
Oleg Shevelev, 2015-08-20
@mantyr

Schoolboy, you opened a ton of related questions on one task... learn how to group data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question