在使用node tools/initdb.js初始化数据库的时候报错

在使用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
  1. 因为里面有两个字段的类型是【timestamp】
    把其中的一个字段类型改成【datetime】
  2. 还可以去server文件夹下的tools
    将里面的cAuth.sql里面的字段类型也改成【datetime】

之后将创表语句添加到Navicat的里面就可以创建表成功了

然后使用npm run dev可以启动就证明成功了
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值