第二个CREATE语句中的Mysql Create Table错误

时间:2018-02-25 22:49:16

标签: mysql node.js mariadb

我正在尝试编写一个脚本来导入Mysql DB结构。我已经通过PhpMyAdmin和节点npm模型sqldump导出了数据库SQL。在尝试创建第二个表时,两者都会产生相同的错误。这似乎不是特定于表的 - 我可以混合使用表(我在此DB中有20个表)并且总是在第二个CREATE TABLE语句中遇到相同的错误。

任何人都可以指出我遇到了一些我想念的蠢事吗?

错误是:

{ Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CREATE TABLE IF NOT EXISTS `autoresponses` (
  `id` bigint(20) NOT NULL AUTO_INC' at line 14
    at PromiseConnection.query (D:\dev-mysql-update\node_modules\mysql2\promise.js:75:20)
    at D:\dev-mysql-update\index.js:157:7
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
  message: 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near \'CREATE TABLE IF NOT EXISTS `autoresponses` (\n  `id` bigint(20) NOT NULL AUTO_INC\' at line 14',
  code: 'ER_PARSE_ERROR',
  errno: 1064,
  sqlState: '#42000' }

前两个表是:

CREATE TABLE IF NOT EXISTS `autoresponders` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `uuid` char(36) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL,
  `archived` tinyint(1) NOT NULL DEFAULT '0',
  `title` varchar(255) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  `deleted_at` datetime DEFAULT NULL,
  `client_id` bigint(20) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `client_id` (`client_id`),
  CONSTRAINT `autoresponders_ibfk_1` FOREIGN KEY (`client_id`) REFERENCES `clients` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `autoresponses` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `uuid` char(36) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL,
  `archived` tinyint(1) NOT NULL DEFAULT '0',
  `hours_delay` int(11) DEFAULT NULL,
  `status` varchar(255) DEFAULT 'active',
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  `deleted_at` datetime DEFAULT NULL,
  `autoresponder_id` bigint(20) DEFAULT NULL,
  `notification_id` bigint(20) DEFAULT NULL,
  `client_id` bigint(20) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `autoresponses_autoresponder_id_notification_id_unique` (`autoresponder_id`,`notification_id`),
  KEY `notification_id` (`notification_id`),
  CONSTRAINT `autoresponses_ibfk_1` FOREIGN KEY (`autoresponder_id`) REFERENCES `autoresponders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `autoresponses_ibfk_2` FOREIGN KEY (`notification_id`) REFERENCES `notifications` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

提前致谢, 安迪

1 个答案:

答案 0 :(得分:-2)

您的表名应在括号内。