无法创建表(错误150)Openshift的phpmyadmin

时间:2014-08-27 03:23:18

标签: sql mysqli openshift

这是我的架构:

-- Table 'users'
CREATE TABLE IF NOT EXISTS `users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) COLLATE utf8_bin NOT NULL,
  `password` varchar(100) COLLATE utf8_bin NOT NULL,
  `registrationDate` datetime NOT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1;

CREATE TABLE IF NOT EXISTS tasks (
  id bigint(20) NOT NULL AUTO_INCREMENT,
  description TEXT,
  title TEXT,
  type TEXT,
  createdDate DATETIME NOT NULL,
  finishedDate DATETIME,
  user_id bigint(20) NOT NULL,
  PRIMARY KEY (id),
  CONSTRAINT user_fk FOREIGN KEY (user_id) REFERENCES USERS(ID) ON DELETE CASCADE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1;

当我尝试创建“任务”表时,我不断得到错误150。我是SQL的新手,无法弄清楚为什么会发生这种情况。

感谢任何帮助,谢谢!

1 个答案:

答案 0 :(得分:1)

看起来像openshift上的phpmyadmin是区分大小写的,如果你深入研究错误,你会得到这个:

LATEST FOREIGN KEY ERROR
------------------------
140827 10:52:57 Error in foreign key constraint of table testing/tasks:
 FOREIGN KEY (user_id) REFERENCES USERS(ID) ON DELETE CASCADE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1:
Cannot resolve table name close to:
(ID) ON DELETE CASCADE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1

在下面的代码中,请注意我在REFERENCES后的第二个表创建代码中将USERS更改为用户 看起来这段代码有效:

CREATE TABLE IF NOT EXISTS `users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) COLLATE utf8_bin NOT NULL,
  `password` varchar(100) COLLATE utf8_bin NOT NULL,
  `registrationDate` datetime NOT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1;

CREATE TABLE IF NOT EXISTS tasks (
  id bigint(20) NOT NULL AUTO_INCREMENT,
  description TEXT,
  title TEXT,
  type TEXT,
  createdDate DATETIME NOT NULL,
  finishedDate DATETIME,
  user_id bigint(20) NOT NULL,
  PRIMARY KEY (id),
  CONSTRAINT user_fk FOREIGN KEY (user_id) REFERENCES users(ID) ON DELETE CASCADE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1;