MySQL, the same table multiple timesatmp fields set default, often an error.
A table can have only one field that sets default.
But sometimes only one field setting default also complains.
Will report: incorrect table definition; There can be only one TIMESTAMP column with Current_timestamp in DEFAULT or on UPDATE clause
But checking the code, found that only one timestamp set default.
For example:
The code is as follows |
Copy Code |
Create Table Dxs_product ( pid int NOT NULL auto_increment comment ' Product ID ', pname & nbsp; varchar comment ' product name ', istop int Comment ' sticky ', begintoptime timestamp comment ' Sticky time ' , endtoptime timestamp comment ' Sticky time ', publishtime Timestamp default Current_ TIMESTAMP comment ' release time ', primary KEY (PID) |
The reason is that when you set a timestamp to on Updatecurrent_timestamp, the other timestamp fields need to explicitly set the default value
But if you have two timestamp fields, but only the first one is set to Current_timestamp and the second does not have a default, MySQL can also build the table, but the reverse is not ...
Change into:
The code is as follows |
Copy Code |
Create Table Dxs_product ( pid int NOT NULL auto_increment comment ' Product ID ', pname & nbsp; varchar comment ' product name ', istop int Comment ' sticky ', publishtime timestamp default Current_timestamp comment ' release time ', begintoptime Timestamp comment ' sticky time ', endtoptime Timestamp comment ' sticky time ', primary KEY (PID) |
There will be no more errors.
The first timestamp is set to default, and the following settings default is not available. And you can only have one column set default.