(上图是初始的sql文件的内容)
在开发微信小程序时,需要导入.sql文件,但是最一开始导入的时候没有任何改动进行了导入,报错如下
PS E:\weichatApp\my-project\server> node tools/initdb.js
======================================
开始初始化数据库...
准备读取 SQL 文件:E:\weichatApp\my-project\server\tools\cAuth.sql
开始执行 SQL 文件...
Unhandled rejection Error: Error: /*
Navicat Premium Data Transfer
Source Server : Localhost
Source Server Type : MySQL
Source Server Version : 50717
Source Host : localhost
Source Database : cAuth
Target Server Type : MySQL
Target Server Version : 50717
File Encoding : utf-8
Date: 08/10/2017 22:22:52 PM
*/
SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for `cSessionInfo`
-- ----------------------------
DROP TABLE IF EXISTS `cSessionInfo`;
CREATE TABLE `cSessionInfo` (
`open_id` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
`uuid` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
`skey` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`last_visit_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`session_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
`user_info` varchar(2048) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`open_id`),
KEY `openid` (`open_id`) USING BTREE,
KEY `skey` (`skey`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='会话管理用户信息';
SET FOREIGN_KEY_CHECKS = 1;
- ER_TOO_MUCH_AUTO_TIMESTAMP_COLS: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
at E:\weichatApp\my-project\server\tools\initdb.js:41:11
at tryCatcher (E:\weichatApp\my-project\server\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (E:\weichatApp\my-project\server\node_modules\bluebird\js\release\promise.js:547:31)
at Promise._settlePromise (E:\weichatApp\my-project\server\node_modules\bluebird\js\release\promise.js:604:18)
at Promise._settlePromise0 (E:\weichatApp\my-project\server\node_modules\bluebird\js\release\promise.js:649:10)
at Promise._settlePromises (E:\weichatApp\my-project\server\node_modules\bluebird\js\release\promise.js:725:18)
at _drainQueueStep (E:\weichatApp\my-project\server\node_modules\bluebird\js\release\async.js:93:12)
at _drainQueue (E:\weichatApp\my-project\server\node_modules\bluebird\js\release\async.js:86:9)
at Async._drainQueues (E:\weichatApp\my-project\server\node_modules\bluebird\js\release\async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (E:\weichatApp\my-project\server\node_modules\bluebird\js\release\async.js:15:14)
at processImmediate (internal/timers.js:461:21)
然后发现是时间戳的问题,原文件中使用的是timestamp,
但是我的数据库版本是mysql5.5,需要把timestamp改成datatime,
改完之后发现报错如下,
1067 - Invalid default value for 'create_time'
,然后再次对sql语句进行更改,
然后再次执行命令
node tools/initdb.js
就可以看到执行成功的美丽画面啦!