将新的枚举列添加到现有 table

Adding new enum column to an existing table

我正在尝试使用此查询向我的 table 添加一个 gender 列:

ALTER TABLE QRCodeUser ADD gender CHAR(1) enum('M','F') NOT NULL;

我收到这个错误:

#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 'enum('M','F') NOT NULL' at line 1

我的错误是什么?

试试这个(你不需要指定大小,char(1)):

ALTER TABLE QRCodeUser ADD gender  enum('M','F') NOT NULL;

语法的正确用法:

ALTER TABLE table_name ADD column_name  enum(`field1`,`field2`,...);