数据库导入情况


Database import situation

Mysql不想将此数据库添加到我的localhost数据库部分。

我做错什么了吗?

db.sql本教程:https://github.com/samanz/cakecart

错误:

SQL query:
CREATE TABLE `categories` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 50 ) NULL default NULL ,
`parent_id` INT( 11 ) UNSIGNED default '0',
`order` INT( 3 ) default '0',
`image` VARCHAR( 50 ) NULL default NULL ,
`ids` VARCHAR( 225 ) NULL default NULL ,
`url` VARCHAR( 255 ) NULL default NULL ,
PRIMARY KEY ( `id` ) ,
FOREIGN KEY ( `parent_id` ) REFERENCES categories( `id` ) ,
UNIQUE KEY `url` ( `url` )
);
MySQL said: Documentation
#1005 - Can't create table 'cake_cart.categories' (errno: 150) 

错误150是一个外键问题。可能由引起

FOREIGN KEY ( `parent_id` ) REFERENCES categories( `id` ) ,

不能对正在创建的同一个表进行"外键"引用。只需对parent_id列进行索引即可。

KEY `parent_id` ( `parent_id` ) ,

应该是这样的。。。

CREATE TABLE IF NOT EXISTS `categories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `parent_id` int(11) unsigned NOT NULL DEFAULT '0',
  `order` int(3) NOT NULL DEFAULT '0',
  `img` varchar(50) NOT NULL,
  `ids` varchar(255) NOT NULL,
  `url` varchar(255) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `url` (`url`),
  KEY `parent_id` (`parent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

我更新了结构,并在我的数据库上运行它,它起了作用。