这是我的桌子:
DROP TABLE IF EXISTS `tbl_comments`;
CREATE TABLE IF NOT EXISTS `tbl_comments` (
`id` int(11) NOT NULL auto_increment,
`topic_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`text` text NOT NULL,
`create_dt` datetime NOT NULL,
`update_dt` timestamp NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `topic_id_2` (`topic_id`),
KEY `user_id` (`user_id`),
CONSTRAINT `tbl_comments_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `tbl_users` (`id`),
CONSTRAINT `tbl_comments_ibfk_1` FOREIGN KEY (`topic_id`) REFERENCES `tbl_topics` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `tbl_users`;
CREATE TABLE IF NOT EXISTS `tbl_users` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(20) NOT NULL default '',
`password` varchar(128) NOT NULL default '',
`email` varchar(128) NOT NULL default '',
`activkey` varchar(128) NOT NULL default '',
`superuser` int(1) NOT NULL default '0',
`status` int(1) NOT NULL default '0',
`create_at` timestamp NOT NULL default CURRENT_TIMESTAMP,
`lastvisit_at` timestamp NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
UNIQUE KEY `user_username` (`username`),
UNIQUE KEY `user_email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `tbl_topics`;
CREATE TABLE IF NOT EXISTS `tbl_topics` (
`id` int(11) NOT NULL auto_increment,
`group_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`header` varchar(255) NOT NULL,
`text` text NOT NULL,
`create_dt` datetime NOT NULL,
`update_dt` timestamp NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
KEY `group_id` (`group_id`),
CONSTRAINT `tbl_topics_ibfk_1` FOREIGN KEY (`group_id`) REFERENCES `tbl_groups` (`id`),
CONSTRAINT `tbl_topics_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `tbl_users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
现在我尝试导入时出错:
#1005 – 无法创建表’kobeco_yii.tbl_comments'(错误号:150)(详细信息:Percona-XTradB,支持事务,行级锁定和外键)
解决方法:
您正试图在其他表之前创建tbl_comments.对于外键约束,tbl_comments需要表tbl_users和tbl_topics.
尝试将tbl_comments的CREATE TABLE移动到其他项下面.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。