我是否应该能够使用文本值更新MySQL枚举类型?

I'm trying to update the value in a MYSQL enum field from PHP via Doctrine (5.3 and 1.2 respectively).

I get an error when I try and do this:

    $q = Doctrine_Query::create()
            ->update('StMessages')
            ->set('status','new')
            ->where('message_id = ?',$msg_id);

I get a sql state error telling me that the column 'new' does not exist. If I enter 3 instead of new (presumably the internal index of the 'new' value), then the query works. In fact it happens in a SQL client too so perhaps this is a quirk of this version of MySQL? Its 5.1.45.

Anyone know if this is how MySQL is supposed to treat enums or if this is more likely a Doctrine issue? I have 'use_native_enum' set to true.

2个回答



我认为这实际上是一个与更新字段值时引用字符串有关的问题。 我不确定Doctrine或我是否有过错。</ p>
</ div>

展开原文

原文

I think this was actually an issue relating to the quoting of strings when updating the field's values. I'm not sure if Doctrine or I was at fault.



给定一个表</ p>

 创建表测试(
enumfield enum('a ','b','c')
);
</ code> </ pre>

你应该能够做到</ p>

 更新测试集enumfield ='a'; 
</ code> </ pre>

这是num字段的全部内容 - 不必弄乱索引等等。</ p>

你的枚举字段的确切定义是什么?</ p>
</ div>

展开原文

原文

Given a table

create table test (
     enumfield enum('a','b','c')
);

you should be able to do

update test set enumfield='a';

which is the whole point of the num field - not having to mess with indexes and whatnot.

What's the exact definition of your enum field?

du656637962
du656637962 实际上它的状态枚举('被拒绝','提升','新')COLLATE utf8_unicode_ci NOT NULL DEFAULT'new',
9 年多之前 回复
duanjiao5261
duanjiao5261 谢谢你回复Marc! “状态ENUM('晋升','拒绝','新')DEFAULT'new'”是枚举字段的定义
9 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问