Question

J'ai un tableau censé suivre les jours et les coûts d'expédition des produits d'un fournisseur à un autre.Nous avons (brillamment :p) stocké à la fois les fournisseurs d'expédition (FedEx, UPS) et les fournisseurs de manutention des produits (Think...Dunder Mifflin) dans une table "VENDOR".J'ai donc trois colonnes dans ma table SHIPPING_DETAILS qui font toutes référence à VENDOR.no.Pour une raison quelconque, MySQL ne me permet pas de définir les trois comme clés étrangères.Des idées?

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;

Modifié pour supprimer la double définition de clé primaire...


Ouais, malheureusement, cela n'a pas résolu le problème.Maintenant, j'obtiens :

Impossible de créer la table './SUPPRIMER MON NOM DE DB/Shipping_grid.frm '(errno:150)

Faire un phpinfo() me dit ceci pour mysql :

API cliente version 5.0.45

Oui, le VENDOR.no est de type int(6).

Était-ce utile?

La solution

Vous avez défini la clé primaire deux fois.Essayer:

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;

La clé primaire VENDOR doit être INT(6) et les deux tables doivent être de type InnoDB.

Autres conseils

J'ai exécuté le code ici et le message d'erreur indique (et c'est vrai !) que vous définissez identifiant champ deux fois comme clé primaire.

Pouvez-vous fournir la définition du tableau des fournisseurs

Je l'ai compris.La table VENDOR était MyISAM...(modifié votre réponse pour me dire de les rendre tous les deux INNODB ;))

(n'importe quelle raison pas pour simplement basculer le type VENDOR sur INNODB ?)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top