mysql - 无效的默认值

标签 mysql

MySQL 发行版 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)
);

是什么导致了这个问题?以及如何修复?

最佳答案

默认值 '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)
);

关于mysql - 无效的默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20372881/

相关文章:

Mysql - 如何将列的值分组为最小-最大范围?

mysql - 如何在子查询中左连接计数

mysql - 将 AESCipher 对象存储在 mySQL 中

Python-插入数据库表

php - 如何对 MySQL 数据库中的行进行排序

mysql - Excel-Vba 连接 Mysql localhost 失败

MySQL Batched Key Access - 没有好处?

mysql - MySQL 数据库是否优化连接本身,还是我们必须指定连接顺序?

mysql - 在SQL Cloud第二代中创建数据库

php - 如何使用数组数据查询以在 PHP 中获取另一个数据