【问题标题】:phpmyadmin Ondelete cascade not workingphpmyadmin Ondelete 级联不起作用
【发布时间】:2012-01-17 06:10:46
【问题描述】:

我有三个表 1) product, 2)product_x, 3) product_y。我已经为这三个表设置了主键。表格是

1) 产品:id、名称、product_type、created_at 2) product_x : id, product_id,description, created_at 3) product_y : id,product_id,description, created_at

product_x 和 product_y 表中的 product_id 表是来自表 product 的外部引用。如果 product_type=1 条目将转到 product_x,如果 product_type=0 条目将转到 product_1。所以这里我的问题是我已经为这两个表的外键引用设置了级联删除。但是当我从 product_x 或 product_y 中删除一个条目时,产品表中的相应 id 不会被删除。这意味着级联删除不起作用。我需要你们的帮助,请帮助。

这是我的产品表。

--
-- Table structure for table `product`
--

CREATE TABLE IF NOT EXISTS `product` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `code` varchar(100) NOT NULL,
  `description` text NOT NULL,
  `product_type` tinyint(4) NOT NULL COMMENT '1=pronova product,2=doctor product',
  `ingredients` varchar(200) NOT NULL,
  `directions` varchar(200) NOT NULL,
  `status` tinyint(1) NOT NULL COMMENT '0=inactive,1=active',
  `created_at` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=67 ;

我的 product_x 表

--

-- 表product_x的表结构

CREATE TABLE IF NOT EXISTS `product_x` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `inventory_id` int(11) NOT NULL,
  `doctor_id` int(11) NOT NULL,
  `stock` varchar(20) NOT NULL,
  `image` varchar(50) NOT NULL,
  `small_image` varchar(100) NOT NULL,
  `sail_price` float DEFAULT NULL,
  `acquire_price` float DEFAULT NULL,
  `created_at` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `product_id` (`product`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

我的 product_y 表是

CREATE TABLE IF NOT EXISTS `product_y` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `inventory_id` int(11) NOT NULL,
  `specialization_type` int(11) NOT NULL,
  `stock` varchar(20) NOT NULL,
  `image` varchar(100) NOT NULL,
  `unit_credit_value` int(11) NOT NULL,
  `suggested_price` float NOT NULL,
  `list_price` float DEFAULT NULL COMMENT 'the price which this product sold if pronova sold this',
  `created_at` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `inventory_id` (`product`),
  KEY `FK50E07CF68B1B2BCE` (`inventory_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

【问题讨论】:

  • 如果您可以发布您的CREATE TABLE 声明,它可能会有所帮助。
  • 请显示这些语句的输出 - SHOW CREATE TABLE product;SHOW CREATE TABLE product_x;SHOW CREATE TABLE product_y;
  • @anoopkattodi,表 product_x 在“product”列上有索引,但表中没有这样的列。 product_y 也是如此。另外,product_x 和 product_y 中的哪个特定列引用了产品 ID?

标签: mysql phpmyadmin


【解决方案1】:

检查以确保您使用的是 InnoDB 而不是 MyISAM,如果您确实无法控制它,您可以编写一个触发器,如下所述:

How to use delete cascade on MySQL MyISAM storage engine?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-28
    • 1970-01-01
    • 1970-01-01
    • 2016-10-24
    • 1970-01-01
    • 2015-03-25
    • 2014-07-01
    • 1970-01-01
    相关资源
    最近更新 更多