比如在創建用戶表的過程中,涉及到設置性別:
CREATE TABLE imooc_user(
id int unsigned auto_increment key,
username varchar(20) not null unique,
password char(32) not null,
sex enum('保密','男','女')not null,
face varchar(50) not null,
regTime int unsigned not null
);
(sex enum('男','女','保密')not null default '保密',)剛開始我一直是這樣寫的,于是一直報錯。。。后來在網上看到,MySQL中enum類型的字段不能顯式設置默認值,默認為第一個值,比如你寫的‘男’。若要把默認設置成“保密”,可以把“保密”放在第一個位置。
于是問題就解決了!
轉自本人博客:http://blog.163.com/qianshiguang_wa/blog/static/237777152201523134335388