MYSQL MULTIPLE FOREAIGN KEYS get无法添加外键约束

时间:2016-07-19 23:57:10

标签: mysql foreign-keys

CREATE TABLE customer (    
    customer_id INT NOT NULL,     
    last_name VARCHAR(25) NOT NULL,      
    first_name VARCHAR(25) NOT NULL,      
    street_address VARCHAR(25) NOT NULL,      
    apt_number INT NULL,      
    city VARCHAR(20) NOT NULL,      
    state VARCHAR(2) NOT NULL,      
    zip_code INT NULL,      
    home_phone VARCHAR(12) NOT NULL,      
    mobile_phone VARCHAR(12) NULL,      
    other_phone VARCHAR(12) NULL,      
    PRIMARY KEY(customer_id)    
);    

CREATE TABLE donut_order(      
    donut_order_id INT NOT NULL,      
    customer_id INT NOT NULL,      
    order_date DATE NOT NULL,      
    special_handling_notes VARCHAR(255) NULL,      
    PRIMARY KEY(donut_order_id),      
    FOREIGN KEY (customer_id)      
    REFERENCES customer (customer_id)      
    ON DELETE CASCADE      
    ON UPDATE CASCADE
);

CREATE TABLE donut_order_item (      
    donut_order_id INT NOT NULL,      
    donut_id INT NOT NULL,      
    qty INT NOT NULL,     
    PRIMARY KEY(donut_order_ID, donut_id),      
    UNIQUE INDEX(donut_id, donut_order_id),      
    CONSTRAINT donut_order FOREIGN KEY (donut_order_id)     
    REFERENCES donut_order (donut_order_id)      
    ON DELETE RESTRICT      
    ON UPDATE RESTRICT,

    CONSTRAINT donut FOREIGN KEY (donut_id)      
    REFERENCES donut (donut_id)      
    ON DELETE RESTRICT  
    ON UPDATE RESTRICT
);

1 个答案:

答案 0 :(得分:0)

尝试使用用户界面而不是它可以帮助您解决此问题。 喜欢这个:

enter image description here