2014-05-15 5 views
9

내 데이터베이스는 MySql 5.6입니다.MySQL - TIMESTAMP (3)의 기본값

TIMESTAMP (3) 유형의 속성 인 CURRENT_TIMESTAMP를 기본값으로 사용하고 싶습니다.

ERROR 1067 (42000): Invalid default value for 'updated'

내가 CURRENT_TIMESTAMP는 두 번째의 정밀도에 있기 때문에이 생각 :

는하지만이 오류가 발생합니다.

소수부가있는 timestamp의 기본값으로 어떻게 현재 시간을 설정할 수 있습니까?

+0

3를 필요가 없으므로 첫 번째 시도 TI MESTAMP (3). 또한 CURRENT_TIMESTAMP를 사용하는 테이블에 필드가 하나만 있는지 확인하십시오. –

+0

문제는 mysql 새 버전에 기본값으로 추가 된 마이크로 초로 인한 것입니다. 해결책은 http://tekina.info/default-datetime-timestamp-issue-mysql-upgrading-5-6/을 참조하십시오. –

답변

12
timestamp에 대한 문서 당으로

datetime 유형 열 :

If a TIMESTAMP or DATETIME column definition includes an explicit fractional seconds precision value anywhere, the same value must be used throughout the column definition.

This is permitted:

CREATE TABLE t1 (
    ts TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) 
); 

다른 예 :

mysql> create table tbl_so_q23671222_1(ts timestamp(3) default now()); 
ERROR 1067 (42000): Invalid default value for 'ts' 

mysql> create table tbl_so_q23671222_1(ts timestamp(3) default now(3)); 
Query OK, 0 rows affected (0.59 sec) 

mysql> create table tbl_so_q23671222_2(ts timestamp(3) default current_timestamp); 
ERROR 1067 (42000): Invalid default value for 'ts' 

mysql> create table tbl_so_q23671222_2(ts timestamp(3) default current_timestamp(3)); 
Query OK, 0 rows affected (0.38 sec) 

mysql> desc tbl_so_q23671222_1; 
+-------+--------------+------+-----+----------------------+-------+ 
| Field | Type   | Null | Key | Default    | Extra | 
+-------+--------------+------+-----+----------------------+-------+ 
| ts | timestamp(3) | NO |  | CURRENT_TIMESTAMP(3) |  | 
+-------+--------------+------+-----+----------------------+-------+ 
1 row in set (0.01 sec) 

mysql> desc tbl_so_q23671222_2; 
+-------+--------------+------+-----+----------------------+-------+ 
| Field | Type   | Null | Key | Default    | Extra | 
+-------+--------------+------+-----+----------------------+-------+ 
| ts | timestamp(3) | NO |  | CURRENT_TIMESTAMP(3) |  | 
+-------+--------------+------+-----+----------------------+-------+ 
1 row in set (0.01 sec) 

를 참조하십시오
Initialization and Updating for TIMESTAMP and DATETIME