执行此声明时:
ALTER TABLE person MODIFY COLUMN subcommittee
ENUM('Arts','Bus','HC','IA','Pol','ST','Floater','Student') NULL DEFAULT NULL;
回应是
2801 row(s) affected Records: 2801 Duplicates: 0 Warnings: 0
然后这句话:
update person set subcommittee = 'Student' where person_pk = 1381;
始终会出现此错误消息:
Error Code: 1265. Data truncated for column 'subcommittee' at row 1
(第1381人在数据库中,如果您想知道,或者我甚至不会收到此错误消息。)
选择其他枚举有效:
update person set subcommittee = 'Floater' where person_pk = 1381;
1 row(s) affected Rows matched: 1 Changed: 1 Warnings: 0
当我使用PDO从我的PHP应用程序收到错误时,我首先注意到了这一点,但随后在MySQLWorkbench中重现了它,从中获取了上述内容。
也许完全删除该列并重新定义它会解决问题,但这是一个实时数据库,我只想在其中添加一个额外的枚举值(学生)。
我尝试重新输入alter语句,将其复制到文本编辑器以检查字符,以及一些其他的东西来排除值中奇怪的不可见字符。我还重新安排了值:
ALTER TABLE person MODIFY COLUMN subcommittee
ENUM('Arts','Bus','HC','IA','Pol','ST', 'Student','Floater') NULL DEFAULT NULL;
没有快乐。
我在谷歌搜索时看到了一些与修改枚举列相关的错误。有谁知道这是一个MySQL错误吗?
(MySQL版本5.5.28。)
一些人要求的一些数据:
mysql> describe person;
+------------------------------+-------------------------------------------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------------------+-------------------------------------------------------------+------+-----+---------+----------------+
| person_pk | int(11) | NO | PRI | NULL | auto_increment |
| name_last | varchar(255) | NO | MUL | | |
| name_first | varchar(255) | YES | | NULL | |
| name_index | int(11) | NO | | 0 | |
| name_middle | varchar(255) | YES | | NULL | |
| name_spouse_or_partner_first | varchar(255) | YES | | NULL | |
| name_spouse_or_partner_last | varchar(255) | YES | | NULL | |
| name_legal_first | varchar(255) | YES | | NULL | |
| name_legal_middle | varchar(255) | YES | | NULL | |
| name_legal_last | varchar(255) | YES | | NULL | |
| prefix | varchar(255) | YES | | NULL | |
| suffix | varchar(255) | YES | | NULL | |
| salutation | varchar(255) | YES | | NULL | |
| home_street1 | varchar(255) | YES | | NULL | |
| home_street2 | varchar(255) | YES | | NULL | |
| home_city | varchar(255) | YES | | NULL | |
| home_state | varchar(255) | YES | | NULL | |
| home_zip | varchar(255) | YES | | NULL | |
| home_country | varchar(255) | YES | | NULL | |
| work_org | varchar(255) | YES | | NULL | |
| work_street1 | varchar(255) | YES | | NULL | |
| work_street2 | varchar(255) | YES | | NULL | |
| work_city | varchar(255) | YES | | NULL | |
| work_state | varchar(255) | YES | | NULL | |
| work_zip | varchar(255) | YES | | NULL | |
| work_country | varchar(255) | YES | | NULL | |
| phone_home | varchar(255) | YES | | NULL | |
| phone_work | varchar(255) | YES | | NULL | |
| phone_mobile | varchar(255) | YES | | NULL | |
| phone_fax | varchar(255) | YES | | NULL | |
| phone5 | varchar(255) | YES | | NULL | |
| phone6 | varchar(255) | YES | | NULL | |
| email | varchar(255) | YES | | NULL | |
| email2 | varchar(255) | YES | | NULL | |
| website | varchar(255) | YES | | NULL | |
| preferred_communication | enum('home','work','mobile','email','mail','special') | YES | | NULL | |
| preferred_communication_text | varchar(255) | YES | | NULL | |
| preferred_address | enum('home','work') | YES | | NULL | |
| use_housing | tinyint(1) | YES | | NULL | |
| smoker | tinyint(1) | YES | | NULL | |
| pet_allergies | tinyint(1) | YES | | NULL | |
| pets | tinyint(1) | YES | | NULL | |
| kids | tinyint(1) | YES | | NULL | |
| physical_considerations | text | YES | | NULL | |
| dietary_needs | text | YES | | NULL | |
| appellation | varchar(255) | YES | | NULL | |
| bio | text | YES | | NULL | |
| photo | varchar(255) | YES | | NULL | |
| include_in_directory | tinyint(1) | YES | | NULL | |
| participant_notes | text | YES | | NULL | |
| contact_notes | text | YES | | NULL | |
| available_1A | tinyint(1) | YES | | NULL | |
| available_1P | tinyint(1) | YES | | NULL | |
| available_2A | tinyint(1) | YES | | NULL | |
| available_2P | tinyint(1) | YES | | NULL | |
| available_3A | tinyint(1) | YES | | NULL | |
| available_3P | tinyint(1) | YES | | NULL | |
| available_4A | tinyint(1) | YES | | NULL | |
| available_4P | tinyint(1) | YES | | NULL | |
| available_5A | tinyint(1) | YES | | NULL | |
| available_5P | tinyint(1) | YES | | NULL | |
| interest_x_dis | tinyint(1) | YES | | NULL | |
| interest_arts | tinyint(1) | YES | | NULL | |
| interest_bus | tinyint(1) | YES | | NULL | |
| interest_hc | tinyint(1) | YES | | NULL | |
| interest_ia | tinyint(1) | YES | | NULL | |
| interest_med | tinyint(1) | YES | | NULL | |
| interest_pol | tinyint(1) | YES | | NULL | |
| interest_st | tinyint(1) | YES | | NULL | |
| venue_manager | tinyint(1) | YES | | NULL | |
| committee_arts | tinyint(1) | YES | | NULL | |
| committee_bus | tinyint(1) | YES | | NULL | |
| committee_hc | tinyint(1) | YES | | NULL | |
| committee_ia | tinyint(1) | YES | | NULL | |
| committee_pol | tinyint(1) | YES | | NULL | |
| committee_st | tinyint(1) | YES | | NULL | |
| committee_students | tinyint(1) | YES | | NULL | |
| committee_housing | tinyint(1) | YES | | NULL | |
| committee_moderator | tinyint(1) | YES | | NULL | |
| committee_volunteer | tinyint(1) | YES | | NULL | |
| committee_fundraising | tinyint(1) | YES | | NULL | |
| committee_office | tinyint(1) | YES | | NULL | |
| committee_other | tinyint(1) | YES | | NULL | |
| committee_notes | text | YES | | NULL | |
| houser_fk | int(11) | YES | MUL | NULL | |
| housed_fk | int(11) | YES | MUL | NULL | |
| contact_fk | int(11) | YES | MUL | NULL | |
| hyphen_fk | int(11) | YES | MUL | NULL | |
| introduced_by_fk | int(11) | YES | MUL | NULL | |
| committee_contact_fk | int(11) | YES | MUL | NULL | |
| donor | tinyint(1) | YES | | NULL | |
| houser | tinyint(1) | YES | | NULL | |
| moderator | tinyint(1) | YES | | NULL | |
| producer | tinyint(1) | YES | | NULL | |
| committee_member | tinyint(1) | YES | | NULL | |
| participant | tinyint(1) | YES | | NULL | |
| fan | tinyint(1) | YES | | NULL | |
| student | tinyint(1) | YES | | NULL | |
| volunteer | tinyint(1) | YES | | NULL | |
| staff | tinyint(1) | YES | | NULL | |
| companion | tinyint(1) | YES | | NULL | |
| id_number | int(11) | YES | | NULL | |
| deceased | tinyint(1) | YES | | NULL | |
| load_donation | tinyint(1) | YES | | NULL | |
| load_panel | tinyint(1) | YES | | NULL | |
| load_participant | tinyint(1) | YES | | NULL | |
| conversion_note | text | YES | | NULL | |
| replacedby_fk | int(11) | YES | MUL | NULL | |
| companion_to_fk | int(11) | YES | MUL | NULL | |
| name_for_program | varchar(255) | YES | | NULL | |
| gender | enum('male','female') | YES | | NULL | |
| subcommittee | enum('Arts','Bus','HC','IA','Pol','ST','Student','Floater') | YES | | NULL | |
| companion_type | enum('spouse/partner','child','friend') | YES | | NULL | |
| days_here | varchar(6) | YES | | NULL | |
| new_or_returning | enum('new','returning') | YES | | NULL | |
| confirmation_sheet | tinyint(1) | YES | | NULL | |
| bio_in | tinyint(1) | YES | | NULL | |
| photo_in | tinyint(1) | YES | | NULL | |
| birthday | date | YES | | NULL | |
| date_topics_letter_sent | date | YES | | NULL | |
| topics_received | tinyint(1) | YES | | NULL | |
| rating | enum('A','B','C','D','F') | YES | | NULL | |
| flight_info_received | tinyint(1) | YES | | NULL | |
| transportation_email_sent | tinyint(1) | YES | | NULL | |
| bringing_children | tinyint(1) | YES | | NULL | |
| date_address_verfied | date | YES | | NULL | |
+------------------------------+-------------------------------------------------------------+------+-----+---------+----------------+
126 rows in set (0.01 sec)
mysql> select person_pk, subcommittee from person where person_pk = 1381;
+-----------+--------------+
| person_pk | subcommittee |
+-----------+--------------+
| 1381 | Floater |
+-----------+--------------+
1 row in set (0.00 sec)
答案 0 :(得分:1)
这是一个非常敏感的MySQL主题
我写过关于在DBA StackExchange中修改ENUM列表的帖子
Jan 24, 2012
:Is it possible to change ENUM() lists? Oct 05, 2011
:Can I rename the values in a MySQL ENUM column in one query? 使用填充数据执行此操作时存在风险。您应该使用空表完成此操作,然后重新加载表。
答案 1 :(得分:1)
我得出结论,这是一个错误。 MySQL在更改时报告没有错误,并在显示列的详细信息时显示新值,但它不相信新值存在。 RolandoMySQLDBA证实这是一个“敏感话题”(他的话)。
所以,我做的是这个:
创建一个名为“subcommittee2”的新枚举列。
使用旧列(更新人员设置子委员会=子委员会2)更新新列的值。
将'subcommitte'重命名为'subcommittee_old'。
将'subcommittee2'重命名为'subcommittee'。
按应用程序运行确认现在已接受新值。
更新:现在客户端要求另一个枚举,并且使用上面的技术不起作用。这次创建一个新列,传输值,并重命名它不起作用。相同的错误消息。
UPDATE2:所以我创建了新的列'subcommittee2',从旧列填充它,然后就这样离开了。在我的应用程序中,我更改为使用新列名称。呀,但是一个人必须完成一项工作......
UPDATE3:我试图在另一个字段上添加枚举值,并且它有效,所以现在我有了这个理论:新添加的值必须不长于现有值。例如,在这种情况下,最长的值是'已接受',并且我添加了值'hold'和'wait',这很正常。 (回想一下原始错误是“数据被截断”。)
答案 2 :(得分:0)
根据this answer判断,似乎ENUM的先前顺序必须相同,最后的新概率。因此,我会说SHOW CREATE TABLE
查看原始订单的内容,然后将Student
附加到该列表的末尾。