```go
func createTable(db *sql.DB, table string) {
sql := `
DROP TABLE IF EXISTS ` + table + `;
CREATE TABLE ` + table + `(
uid INT(10) NOT NULL AUTO_INCREMENT,
username VARCHAR(64) NULL DEFAULT NULL,
departname VARCHAR(64) NULL DEFAULT NULL,
created DATE NULL DEFAULT NULL,
PRIMARY KEY(uid)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;`
fmt.Println("\n" + sql + "\n")
smt, err := db.Prepare(sql)
checkErr(err)
smt.Exec()
}
```
这是我打印的调试信息:
DROP TABLE IF EXISTS tablea;
CREATE TABLE tablea(
uid INT(10) NOT NULL AUTO_INCREMENT,
username VARCHAR(64) NULL DEFAULT NULL,
departname VARCHAR(64) NULL DEFAULT NULL,
created DATE NULL DEFAULT NULL,
PRIMARY KEY(uid)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
panic: Error 1064: 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 'CREATE TABLE tablea(
uid INT(10) NOT NULL AUTO_INCREMENT,
username VARCHAR(64)' at line 22
这是为什么捏?
确实冗余,我改了之后的错误信息:
```go
DROP TABLE IF EXISTS bac;
CREATE TABLE bac(
uid INT(10) NOT NULL AUTO_INCREMENT,
username VARCHAR(64) DEFAULT NULL,
departname VARCHAR(64) DEFAULT NULL,
created DATE DEFAULT NULL,
PRIMARY KEY(uid)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
panic: Error 1064: 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 'CREATE TABLE bac(
uid INT(10) NOT NULL AUTO_INCREMENT,
username VARCHAR(64) DE' at line 2
```
#9
更多评论