在今天在一個(gè)mysql數(shù)據(jù)表中同時(shí)使用了多個(gè)timesatmp設(shè)置了默認(rèn)值時(shí)發(fā)現(xiàn)提示了mysqltimestamp報(bào)錯(cuò)#1293 - Incorrect table definition; there can be only one TIMESTAMP column with C 了,下面我就我解決些問題具體方法分享給大家吧。
mysql中,同一個(gè)表多個(gè)timesatmp字段設(shè)置default的時(shí)候,經(jīng)常會報(bào)錯(cuò)。.
一個(gè)表只能有一個(gè)設(shè)置default的字段,但是有時(shí)只有一個(gè)字段設(shè)置default也會報(bào)錯(cuò).
會報(bào):Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
但是檢查代碼,發(fā)現(xiàn)只有一個(gè)timestamp設(shè)置了default,例如,代碼如下:
- create table dxs_product
- (
- pid int not null auto_increment comment '產(chǎn)品id',
- pname varchar(300) comment '產(chǎn)品名',
- istop int comment '置頂',
- begintoptime timestamp comment '置頂時(shí)間',
- endtoptime timestamp comment '置頂時(shí)間',
- publishtime timestamp default CURRENT_TIMESTAMP comment '發(fā)布時(shí)間', //開源軟件:Vevb.com
- primary key (pid)
- )
原因是當(dāng)你給一個(gè)timestamp設(shè)置為on updatecurrent_timestamp的時(shí)候,其他的timestamp字段需要顯式設(shè)定default值.
但是如果你有兩個(gè)timestamp字段,但是只把第一個(gè)設(shè)定為current_timestamp而第二個(gè)沒有設(shè)定默認(rèn)值,mysql也能成功建表,但是反過來就不行...
改成如下代碼:
- create table dxs_product
- (
- pid int not null auto_increment comment '產(chǎn)品id',
- pname varchar(300) comment '產(chǎn)品名',
- istop int comment '置頂',
- publishtime timestamp default CURRENT_TIMESTAMP comment '發(fā)布時(shí)間',
- begintoptime timestamp comment '置頂時(shí)間',
- endtoptime timestamp comment '置頂時(shí)間',
- primary key (pid) //開源軟件:Vevb.com
- )
就不報(bào)錯(cuò)了,第一個(gè)timestamp設(shè)置了default才可以,后面的設(shè)置default就不行,而且只能有一列設(shè)置default.
新聞熱點(diǎn)
疑難解答
圖片精選