Multiple foreign keys?

前端 未结 3 1223
-上瘾入骨i
-上瘾入骨i 2021-02-05 09:19

I\'ve got a table that is supposed to track days and costs for shipping product from one vendor to another. We (brilliantly :p) stored both the shipping vendors (FedEx, UPS) wit

相关标签:
3条回答
  • 2021-02-05 09:42

    Can you provide the definition of the VENDOR table

    I figured it out. The VENDOR table was MyISAM... (edited your answer to tell me to make them both INNODB ;) )

    (any reason not to just switch the VENDOR type over to INNODB?)

    0 讨论(0)
  • 2021-02-05 09:44

    You defined the primary key twice. Try:

    CREATE TABLE SHIPPING_GRID(  
        id INT NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'Unique ID for each row',  
        shipping_vendor_no INT(6) NOT NULL COMMENT 'Foreign key to VENDOR.no for the shipping vendor (vendors_type must be 3)',  
        start_vendor_no INT(6) NOT NULL COMMENT 'Foreign key to VENDOR.no for the vendor being shipped from',  
        end_vendor_no INT(6) NOT NULL COMMENT 'Foreign key to the VENDOR.no for the vendor being shipped to',  
        shipment_duration INT(1) DEFAULT 1 COMMENT 'Duration in whole days shipment will take',  
        price FLOAT(5,5) NOT NULL COMMENT 'Price in US dollars per shipment lbs (down to 5 decimal places)',  
        is_flat_rate TINYINT(1) DEFAULT 0 COMMENT '1 if is flat rate regardless of weight, 0 if price is by lbs',  
        INDEX (shipping_vendor_no),  
        INDEX (start_vendor_no),  
        INDEX (end_vendor_no),  
        FOREIGN KEY (shipping_vendor_no) REFERENCES VENDOR (no),  
        FOREIGN KEY (start_vendor_no) REFERENCES VENDOR (no),  
        FOREIGN KEY (end_vendor_no) REFERENCES VENDOR (no)  
    ) TYPE = INNODB;
    

    The VENDOR primary key must be INT(6), and both tables must be of type InnoDB.

    0 讨论(0)
  • 2021-02-05 10:00

    I ran the code here, and the error message showed (and it is right!) that you are setting id field twice as primary key.

    0 讨论(0)
提交回复
热议问题