赞
踩
MySql版本为sql5
该错误源于版本不对应,'utf8mb4'是sql5.6版本以上对应的
解决方法:
一、将版本升级,但在升级过程中注意要卸载干净;
二、将utf8mb4修改为utf8即可;
代码如下:
- CREATE TABLE `product` (
- `product_id` int(10) NOT NULL AUTO_INCREMENT,
- `product_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '产品名称',
- `product_title` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '产品标题',
- `product_price` decimal(10, 2) NULL DEFAULT NULL COMMENT '原价',
- `product_sale_price` decimal(10, 2) NOT NULL COMMENT '促销价',
- `product_create_date` datetime(0) NOT NULL COMMENT '创建日期',
- `product_category_id` int(10) NOT NULL COMMENT '类别id',
- `product_isEnabled` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否可用',
- PRIMARY KEY (`product_id`) USING BTREE,
- INDEX `product_ibfk_1`(`product_category_id`) USING BTREE,
- CONSTRAINT `product_ibfk_1` FOREIGN KEY (`product_category_id`) REFERENCES `category` (`category_id`) ON DELETE CASCADE ON UPDATE RESTRICT
- )
改进后代码:
- CREATE TABLE `product` (
- `product_id` int(10) NOT NULL AUTO_INCREMENT,
- `product_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '产品名称',
- `product_title` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '产品标题',
- `product_price` decimal(10, 2) NULL DEFAULT NULL COMMENT '原价',
- `product_sale_price` decimal(10, 2) NOT NULL COMMENT '促销价',
- `product_create_date` datetime NOT NULL COMMENT '创建日期',
- `product_category_id` int(10) NOT NULL COMMENT '类别id',
- `product_isEnabled` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否可用',
- PRIMARY KEY (`product_id`) USING BTREE,
- INDEX `product_ibfk_1`(`product_category_id`) USING BTREE,
- CONSTRAINT `product_ibfk_1` FOREIGN KEY (`product_category_id`) REFERENCES `category` (`category_id`) ON DELETE CASCADE ON UPDATE RESTRICT
- )
原因:
主要是因为mysql5.7和mysql5.5的datetime、timestamp不兼容,mysql5.7导出的格式为 : datetime(0)而mysql5.5则无法识别该语法
解决方法:1、将导出语句中datetime(0) 改为datetime,或者是timestamp(0) 改为timestamp
2、保持数据库版本一致
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。