Frage

Ich habe eine Tabelle, die Tage und Kosten für den Versand von Produkten von einem Anbieter zum anderen verfolgen soll.Wir haben (genial :p) sowohl die Versandanbieter (FedEx, UPS) als auch die Produktabwicklungsanbieter (Denken Sie...) gespeichert.Dunder Mifflin) in einer „VENDOR“-Tabelle.Ich habe also drei Spalten in meiner Tabelle SHIPPING_DETAILS, die alle auf VENDOR.no verweisen.Aus irgendeinem Grund erlaubt mir MySQL nicht, alle drei als Fremdschlüssel zu definieren.Irgendwelche Ideen?

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;

Bearbeitet, um die doppelte Primärschlüsseldefinition zu entfernen ...


Ja, das hat das Problem leider nicht behoben.Jetzt bekomme ich:

Tabelle kann nicht erstellen './MEINEN DB-NAMEN ENTFERNT/Shipping_grid.frm '(Errno:150)

Wenn ich phpinfo() ausführe, erfahre ich Folgendes für MySQL:

Client-API-Version 5.0.45

Ja, VENDOR.no ist vom Typ int(6).

War es hilfreich?

Lösung

Sie haben den Primärschlüssel zweimal definiert.Versuchen:

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;

Der VENDOR-Primärschlüssel muss INT(6) sein und beide Tabellen müssen vom Typ InnoDB sein.

Andere Tipps

Ich habe den Code hier ausgeführt und die Fehlermeldung zeigte (und das ist richtig!), dass Sie die Einstellung vornehmen Ausweis Feld zweimal als Primärschlüssel.

Können Sie die Definition der Lieferantentabelle angeben?

Ich habe es herausgefunden.Die VENDOR-Tabelle war MyISAM...(habe deine Antwort bearbeitet, um mir mitzuteilen, dass ich sie beide zu INNODB machen soll ;) )

(irgendein Grund nicht einfach den VENDOR-Typ auf INNODB umstellen?)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top