在使用node tools/initdb.js初始化数据库的时候报错
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` datatime NOT NULL,
`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_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'datatime NOT NULL,
`session_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT N' at line 6
at D:\weixinWeb\workspaces\first_demo\server\tools\initdb.js:41:11
at tryCatcher (D:\weixinWeb\workspaces\first_demo\server\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (D:\weixinWeb\workspaces\first_demo\server\node_modules\bluebird\js\release\promise.js:547:31)
at Promise._settlePromise (D:\weixinWeb\workspaces\first_demo\server\node_modules\bluebird\js\release\promise.js:604:18)
at Promise._settlePromise0 (D:\weixinWeb\workspaces\first_demo\server\node_modules\bluebird\js\release\promise.js:649:10)
at Promise._settlePromises (D:\weixinWeb\workspaces\first_demo\server\node_modules\bluebird\js\release\promise.js:725:18)
at _drainQueueStep (D:\weixinWeb\workspaces\first_demo\server\node_modules\bluebird\js\release\async.js:93:12)
at _drainQueue (D:\weixinWeb\workspaces\first_demo\server\node_modules\bluebird\js\release\async.js:86:9)
at Async._drainQueues (D:\weixinWeb\workspaces\first_demo\server\node_modules\bluebird\js\release\async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (D:\weixinWeb\workspaces\first_demo\server\node_modules\bluebird\js\release\async.js:15:14)
at processImmediate (internal/timers.js:456:21)
报这个错误的时候可以去看下
mysql版本问题
5.5版本 |
---|
One TIMESTAMP column in a table can have the current timestamp as the default value for initializing the column, as the auto-update value, or both. It is not possible to have the current timestamp be the default value for one column and the auto-update value for another column. |
5.6.5版本 |
Previously, at most one TIMESTAMP column per table could be automatically initialized or updated to the current date and time. This restriction has been lifted. Any TIMESTAMP column definition can have any combination of DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP clauses. In addition, these clauses now can be used with DATETIME column definitions. For more information, see Automatic Initialization and Updating for TIMESTAMP and DATETIME |
- 因为里面有两个字段的类型是【timestamp】
把其中的一个字段类型改成【datetime】 - 还可以去server文件夹下的tools
将里面的cAuth.sql里面的字段类型也改成【datetime】
之后将创表语句添加到Navicat的里面就可以创建表成功了
然后使用npm run dev
可以启动就证明成功了