mysql - 默认值无效

时间:2013-12-04 10:31:32

标签: mysql

MySQL Distrib 5.5.31

由于字符集不正确,我删除了旧的数据库。所以我尝试创建新的数据库并加载正确的转储。我之前也有一个旧版本的mysql。

创建BD并加载转储时出现以下错误:

ERROR 1067 (42000) at line 225234: Invalid default value for 'ts_created'
ERROR 1146 (42S02) at line 225243: Table 'ardostore.toc_piwik_site' doesn't exist
ERROR 1067 (42000) at line 225252: Invalid default value for 'date_registered'
ERROR 1146 (42S02) at line 225263: Table 'ardostore.toc_piwik_user' doesn't exist

225234:

create table toc_piwik_site (
  idsite int(10) unsigned not null auto_increment,
  name varchar(90) not null,
  main_url varchar(255) not null,
  ts_created timestamp default 'CURRENT_TIMESTAMP' not null,
  feedburnerName varchar(100),
  PRIMARY KEY (idsite)
);

225243:

insert into toc_piwik_site (idsite, name, main_url, ts_created, feedburnerName) values ('1', 'Store Name', 'http://ardostore.com', '2012-10-18 19:58:49', NULL);
drop table if exists toc_piwik_site_url;
create table toc_piwik_site_url (
  idsite int(10) unsigned not null,
  url varchar(255) not null,
  PRIMARY KEY (idsite, url)
);

225252:

create table toc_piwik_user (
  login varchar(100) not null,
  password char(32) not null,
  alias varchar(45) not null,
  email varchar(100) not null,
  token_auth char(32) not null,
  date_registered timestamp default 'CURRENT_TIMESTAMP' not null,
  PRIMARY KEY (login),
  UNIQUE uniq_keytoken (token_auth)
);

225263

insert into toc_piwik_user (login, password, alias, email, token_auth, date_registered) values ('toc_piwik_view', '5f4dcc3b5aa765d61d8327deb882cf99', 'toc_piwik_view', 'sonarius@gmail.com', 'a674bf3fe5d9c0651ac32b28fcbe74f8', '2012-10-18 19:58:49');
drop table if exists toc_piwik_user_dashboard;
create table toc_piwik_user_dashboard (
  login varchar(100) not null,
  iddashboard int(11) not null,
  layout text not null,
  PRIMARY KEY (login, iddashboard)
);

UPD

ERROR 1170 (42000) at line 225099: BLOB/TEXT column 'query' used in key specification without a ke                                         y length

create table toc_piwik_log_profiling (
  query text not null,
  count int(10) unsigned,
  sum_time_ms float,
  UNIQUE query (query)
);

导致这个问题的原因是什么?以及如何解决?

2 个答案:

答案 0 :(得分:7)

默认值'CURRENT_TIMESTAMP'是一个字符串。删除引号,它将起作用:

create table toc_piwik_site (
  idsite int(10) unsigned not null auto_increment,
  name varchar(90) not null,
  main_url varchar(255) not null,
  ts_created timestamp default CURRENT_TIMESTAMP not null,
  feedburnerName varchar(100),
  PRIMARY KEY (idsite)
);

答案 1 :(得分:2)

删除CURRENT_TIMESTAMP周围的'。那些使它成为一个字符串。

像这样编写它:

create table toc_piwik_site (
  idsite int(10) unsigned not null auto_increment,
  name varchar(90) not null,
  main_url varchar(255) not null,
  ts_created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  feedburnerName varchar(100),
  PRIMARY KEY (idsite)
);