gpt4 book ai didi

mysql - 索引: '[column]' 的默认值无效

转载 作者:行者123 更新时间:2023-11-29 17:35:24 24 4
gpt4 key购买 nike

我正在开发一个已有 10 年历史的网络应用程序(!!!)&当前本地运行mysql,版本5.7。

这是我当前正在处理的表格:

CREATE TABLE `processes_history` (
`p_id` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`exec_id` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`feature` varchar(100) NOT NULL DEFAULT '',
`macro` tinyint(1) UNSIGNED NOT NULL DEFAULT '0',
`ts` date NOT NULL DEFAULT '0000-00-00',
`seen` int(10) UNSIGNED NOT NULL DEFAULT '1',
`seen_time` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`focus` int(10) UNSIGNED NOT NULL DEFAULT '0',
`focus_time` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`mouse` int(10) UNSIGNED NOT NULL DEFAULT '0',
`keyboard` int(10) UNSIGNED NOT NULL DEFAULT '0',
`interactive` int(10) UNSIGNED NOT NULL DEFAULT '0',
`interactive_time` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`last_seen` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=MyISAM DEFAULT CHARSET=utf8
PARTITION BY RANGE (TO_DAYS(`ts`))
(
PARTITION p0 VALUES LESS THAN (736695) ENGINE=MyISAM,
PARTITION p201701 VALUES LESS THAN (736726) ENGINE=MyISAM,
PARTITION p201702 VALUES LESS THAN (736754) ENGINE=MyISAM,
PARTITION p201703 VALUES LESS THAN (736785) ENGINE=MyISAM,
PARTITION p201704 VALUES LESS THAN (736815) ENGINE=MyISAM,
PARTITION p201705 VALUES LESS THAN (736846) ENGINE=MyISAM,
PARTITION p201706 VALUES LESS THAN (736876) ENGINE=MyISAM,
PARTITION p201707 VALUES LESS THAN (736907) ENGINE=MyISAM,
PARTITION p201708 VALUES LESS THAN (736938) ENGINE=MyISAM,
PARTITION p201709 VALUES LESS THAN (736968) ENGINE=MyISAM,
PARTITION p201710 VALUES LESS THAN (736999) ENGINE=MyISAM,
PARTITION p201711 VALUES LESS THAN (737029) ENGINE=MyISAM,
PARTITION p201712 VALUES LESS THAN (737060) ENGINE=MyISAM,
PARTITION p201801 VALUES LESS THAN (737091) ENGINE=MyISAM,
PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE=MyISAM
);

--
-- Indexes for dumped tables
--

--
-- Indexes for table `processes_history`
--
ALTER TABLE `processes_history`
ADD PRIMARY KEY (`p_id`,`exec_id`,`feature`,`ts`),
ADD KEY `ts` (`ts`),
ADD KEY `exec_ts` (`exec_id`,`ts`),
ADD KEY `last_seen` (`last_seen`);

p_id、exec_id、ts 添加索引时,我不断收到错误:

ALTER TABLE `dbname`.`processes_history` ADD INDEX `p_id,exec_id,ts` (`p_id`, `exec_id`, `ts`);

Error SQL query:

ALTER TABLE dbname.processes_history ADD INDEX p_id,exec_id,ts(p_id, exec_id, ts) MySQL said: Documentation

1067 - Invalid default value for 'ts'

关注此帖子:https://dba.stackexchange.com/questions/192186/on-create-index-invalid-default-value

据我了解,使用 0000-00-00 作为默认值会破坏“日期”类型,这就是它不起作用的原因。

但我就是不明白这种情况的解决方案是什么。使用 TIMESTAMP 类型代替?

有没有办法在不破坏整个网络应用程序的结构(至少现在)的情况下解决这个问题?很多事情都依赖于该表,我真的不想做一些冒险的事情来按照我想要的方式对其进行索引。

最佳答案

更改 SQL_mode 解决了问题:

我比较了 MySQL 5.7 和 5.6,似乎 5.7 有默认限制:ONLY_FULL_GROUP_BY、STRICT_TRANS_TABLES、NO_ZERO_IN_DATE、NO_ZERO_DATE、ERROR_FOR_DIVISION_BY_ZERO、NO_AUTO_CREATE_USER 和 NO_ENGINE_SUBSTITUTION 设置 ( 0x104 567916)。

在 5.6 上:只需 NO_ENGINE_SUBSTITUTION(mysql 5.6手册https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_zero_in_date)

为了让我的本地 mysql (5.7) 与生产版本 (5.6) 同步工作,我只需将 https://dev.mysql.com/doc/refman/5.6/en/sql-mode.html#sql-mode-setting 更改为 NO_ENGINE_SUBSTITUTION

SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION';
SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION';

您可以在 db-stackexchange 上查看 set mysql_mode 以了解更多信息。

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com