简体   繁体   English

更改外键表名称不能正确更新数据

[英]Changing Foreign Key Table Name Isn't Updating Data Properly

I have the following tables: 我有以下表格:

CREATE TABLE publishers
(
    name        VARCHAR(50)                         NOT NULL,
    status      TINYINT         DEFAULT 1           NOT NULL,
    CONSTRAINT publishers_pk PRIMARY KEY (name)
); 

CREATE TABLE titles
(
    id          INT                 NOT NULL    AUTO_INCREMENT,
    publisher   VARCHAR(50),
    title       VARCHAR(50)         NOT NULL,
    status      ENUM('active', 'announced', 'inactive'),
    discount    TINYINT             NOT NULL,
    CONSTRAINT title_pk PRIMARY KEY (id),
    CONSTRAINT title_fk FOREIGN KEY (publisher)
        REFERENCES publishers (name)
        ON DELETE   SET NULL
        ON UPDATE   CASCADE
);

When I change the "name" in publishers, it isn't changing the "publisher" in the titles table. 当我在发布者中更改“名称”时,它并没有更改titles表中的“发布者”。 Why is the behavior working this way? 为什么行为以这种方式起作用?

Do you know what engine you are using? 你知道你在用什么引擎吗? I read that MySQL with the default engine will parse the foreign key constraints but not actually do anything with them. 我读到具有默认引擎的MySQL将解析外键约束,但实际上不对其执行任何操作。 Is it possible you're using the MyISAM engine? 您可能正在使用MyISAM引擎吗?

http://dev.mysql.com/doc/refman/5.5/en/ansi-diff-foreign-keys.html http://dev.mysql.com/doc/refman/5.5/en/ansi-diff-foreign-keys.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM