百度了很多,添加索引,inndob引擎,数据类型与主表一样,..都无效。有谁还有解决办法?
CREATE TABLE salesrecords(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,merchandiseid INT,merchandiseshortcutname VARCHAR(10),merchandisefullname VARCHAR(30),wholesalequantity INT NOT NULL DEFAULT '0',retailquantity INT NOT NULL DEFAULT '0',saledate DATE,INDEX (merchandiseid),FOREIGN KEY (merchandiseid,merchandiseshortcutname,merchandisefullname) REFERENCES merchandise(id,shortcutname,fullname) ON DELETE RESTRICT ON UPDATE CASCADE);

解决方案 »

  1.   

    show create table merchandise;贴出来以供分析。(id,shortcutname,fullname) 这个创建复合索引了吗?
      

  2.   

    FOREIGN KEY
    1.只能是inndob表;
    2.内外键字段信息要一样。
      

  3.   


    INDEX (merchandiseid,merchandiseshortcutname,merchandisefullname)复合索引后也是150错误
      

  4.   

    这个都考虑了,2个表对应的数据类型一样。都是inndob表
      

  5.   

    CREATE TABLE `merchandise` (
     `id` int(11) NOT NULL auto_increment,
     `shortcutname` varchar(10) NOT NULL,
     `fullname` varchar(30) NOT NULL,
     `res` varchar(30) default NULL,
     `stockquantity` int(11) NOT NULL default '0',
     `price` int(11) NOT NULL default '0',
     `wholesaleprice` int(11) default '0',
     `retailprice` int(11) NOT NULL default '0',
     PRIMARY KEY  (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=gb2312
      

  6.   

    http://www.cnblogs.com/gaoyuchuanIT/articles/2356533.html
      

  7.   

    merchandiseid INT NOT NULL,merchandiseshortcutname VARCHAR(10) NOT NULL
    类型也是一致的
      

  8.   


    要为merchandise创建复合索引????
      

  9.   


    merchandise表的这三个字段创建索引id,shortcutname,fullname