dqcwl02022 2013-08-24 21:08
浏览 87
已采纳

MySQL错误代码1005,SQL状态HY000:无法创建表'cpis.cpis_sudent_profile'(错误号:150)

I need your assistance conditional! I could not determine what the problem is... I think that everything is correct, but MySQL throws an error 1005, SQL state HY000: Can't create table 'cpis.cpis_sudent_profile' (errno: 150)

DROP TABLE IF EXISTS `cpis_users`;
CREATE TABLE `cpis_users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(20) NOT NULL,
  `password` varchar(128) NOT NULL,
  `email` varchar(128) NOT NULL,
  `activkey` varchar(128) NOT NULL DEFAULT '',
  `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `lastvisit_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `status` boolean NOT NULL DEFAULT false,
  `user_type` varchar(128) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`),
  UNIQUE KEY `email` (`email`),
  KEY `status` (`status`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `cpis_countries`;
CREATE TABLE `cpis_countries` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `code` varchar(3) NOT NULL,
  `title_ru` varchar(100) DEFAULT NULL,
  `title_en` varchar(100) DEFAULT NULL,
  `title_cz` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`)
)ENGINE=InnoDB  DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `cpis_programs`;
CREATE TABLE `cpis_programs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title_ru` varchar(100) DEFAULT NULL,
  `description_ru` text DEFAULT NULL,
  `title_en` varchar(100) DEFAULT NULL,
  `description_en` text DEFAULT NULL,
  `title_cz` varchar(100) DEFAULT NULL,
  `description_cz` text DEFAULT NULL,
  `publicated` boolean DEFAULT false,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `cpis_sudent_profile`;
CREATE TABLE `cpis_sudent_profile` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `fname` varchar(100) NOT NULL,
  `pname` varchar(100) NOT NULL,
  `lname` varchar(100) NOT NULL,
  `birthday` date NOT NULL,
  `citizenship` int(11) NOT NULL,
  `sex` varchar(30) NOT NULL,
  `program_id` varchar(100) NOT NULL,
  `owner` int(11) DEFAULT NULL,
  `member` int(11) DEFAULT NULL,
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   PRIMARY KEY (`id`),
   CONSTRAINT `spfk_1` FOREIGN KEY (`user_id`) REFERENCES `cpis_users` (`id`),
   CONSTRAINT `spfk_2` FOREIGN KEY (`citizenship`) REFERENCES `cpis_countries` (`id`),
   CONSTRAINT `spfk_3` FOREIGN KEY (`program_id`) REFERENCES `cpis_programs` (`id`),
   CONSTRAINT `spfk_4` FOREIGN KEY (`owner`) REFERENCES `cpis_users` (`id`),
   CONSTRAINT `spfk_5` FOREIGN KEY (`member`) REFERENCES `cpis_users` (`id`)  
) ENGINE=InnoDB CHARSET=utf8;
  • 写回答

1条回答 默认 最新

  • doxrxwn2252 2013-08-24 21:17
    关注

    program_id varchar(100) should be of the same data type as cpis_programs (id int(11)). By having different types of data, failure to establish the constraint. Example SQL Fiddle.

    ...
    DROP TABLE IF EXISTS `cpis_sudent_profile`;
    
    CREATE TABLE `cpis_sudent_profile` (
      `id` int(10) NOT NULL AUTO_INCREMENT,
      `user_id` int(11) NOT NULL,
      `fname` varchar(100) NOT NULL,
      `pname` varchar(100) NOT NULL,
      `lname` varchar(100) NOT NULL,
      `birthday` date NOT NULL,
      `citizenship` int(11) NOT NULL,
      `sex` varchar(30) NOT NULL,
      /*`program_id` varchar(100) NOT NULL,*/
      `program_id` int(11) NOT NULL,
      `owner` int(11) DEFAULT NULL,
      `member` int(11) DEFAULT NULL,
      `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
       PRIMARY KEY (`id`),
       CONSTRAINT `spfk_1` FOREIGN KEY (`user_id`) REFERENCES `cpis_users` (`id`),
       CONSTRAINT `spfk_2` FOREIGN KEY (`citizenship`) REFERENCES `cpis_countries` (`id`),
       CONSTRAINT `spfk_3` FOREIGN KEY (`program_id`) REFERENCES `cpis_programs` (`id`),
       CONSTRAINT `spfk_4` FOREIGN KEY (`owner`) REFERENCES `cpis_users` (`id`),
       CONSTRAINT `spfk_5` FOREIGN KEY (`member`) REFERENCES `cpis_users` (`id`)  
    ) ENGINE=InnoDB CHARSET=utf8;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?