Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the reason for Mysql error code 1293

Tags:

mysql

Here is the message of mysql error 1293:

SQL Error (1293): Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

what is the reason for mysql only allows one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause per table.

like image 660
solomon_wzs Avatar asked Nov 02 '12 07:11

solomon_wzs


1 Answers

Only one TIMESTAMP field can default to "now" I should say first of all, if you are trying to define more than one MySQL TIMESTAMP fields using CURRENT_TIMESTAMP or "default now", unfortunately that is bad, you can't do it in MySQL I just got this MySQL TIMESTAMP error when trying to create a table like this:

create table users (
    id int unsigned auto_increment not null primary key,
    username varchar(50) not null unique,
    password varchar(40) not null,
    email_address varchar(128) not null unique,
    email_sent timestamp not null,
    last_login timestamp not null default now()
    ) ENGINE = InnoDB;

When I first solved this problem I thought MySQL required the "CURRENT_TIMESTAMP (default now)" field to be declared before any other TIMESTAMP fields, so I solved my problem like this:

create table users (
   id int unsigned auto_increment not null primary key,
   username varchar(50) not null unique,
   password varchar(40) not null,
   email_address varchar(128) not null unique,
   last_login timestamp not null default now(),
   email_sent timestamp not null
 ) ENGINE = InnoDB;
like image 97
Deepu Avatar answered Oct 25 '22 09:10

Deepu