martin j martin j - 1 month ago 6
SQL Question

Cant use ENUM in new tables

After I updated my WAMP server with mysql version 5.7.14, apache version 2.4.23, and php version 7.0.10. Not sure if php version mather but its there if you need it.

After the updated I've not been able to create new tables where one or more of the column uses

ENUM
, after searching about it, I found a thread that recomended using something ells than
ENUM
but since it have been working well so far, I dont see the problem with it(?). After the update I get this 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 '0) NOT NULL ,
`rank` ENUM(0) NOT NULL ,
`avatar` VARCHAR(255) NOT NULL ,
`' at line 13


It works when removing the ENUM columns but I need them. Heres the SQL:

CREATE TABLE `az2983`.`users` (
`id` INT(11) NOT NULL AUTO_INCREMENT ,
`username` VARCHAR(255) NOT NULL ,
`email` VARCHAR(255) NOT NULL ,
`firstname` VARCHAR(255) NOT NULL ,
`lastname` VARCHAR(255) NOT NULL ,
`question` VARCHAR(255) NOT NULL ,
`answer` VARCHAR(255) NOT NULL ,
`ip` INT(25) NOT NULL ,
`active_ip` INT(25) NOT NULL ,
`level` INT(11) NOT NULL ,
`exp` INT(11) NOT NULL ,
`title` ENUM(0) NOT NULL ,
`rank` ENUM(0) NOT NULL ,
`avatar` VARCHAR(255) NOT NULL ,
`bio` VARCHAR(1800) NOT NULL ,
`banner` VARCHAR(255) NOT NULL ,
`f_post` INT(11) NOT NULL ,
`f_threads` INT(11) NOT NULL ,
`post` INT(11) NOT NULL ,
`profile_visible` ENUM(0) NOT NULL ,
`link` VARCHAR(255) NOT NULL ,
`born_date` DATE NOT NULL ,
`active` ENUM(0) NOT NULL ,
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`banned` ENUM(0) NOT NULL ,
`founder` ENUM(0) NOT NULL ,
`awards` INT(11) NOT NULL ,
`friends` INT(11) NOT NULL ,
PRIMARY KEY (`id`)) ENGINE = MyISAM;

Answer

You are using ENUMerations wrong. You can't put in 0 because that's not an ENUM, it's an integer.

Use it like this:

ENUM('x-small', 'small', 'medium', 'large', 'x-large')

See http://dev.mysql.com/doc/refman/5.7/en/enum.html

Comments