2015-11-07 1 views
1

J'essaie de supprimer une colonne de clé étrangère dans une table que j'ai appelée ProductInvoice. La colonne que j'essaie de supprimer s'appelle PersonID et provient de la table Person. Quand je lance la requêteMySql Error 1025

ALTER TABLE ProductInvoice 
DROP COLUMN PersonID; 

Je reçois cette erreur ...

Error Code: 1025. Error on rename of './jkripal/#sql-91c_19ff0' to './jkripal/ProductInvoice' (errno: 150) 

Tous les conseils sur la façon de résoudre cela? J'ai regardé autour de ce site et ne trouve aucune réponse qui m'aide.

Ce sont les résultats de SHOW CREATE TABLE ProductInvoice

'ProductInvoice', 'CREATE TABLE `ProductInvoice` 
(\n `ProductInvoiceID` int(11) NOT NULL AUTO_INCREMENT, 
\n `PersonID` int(11) DEFAULT NULL, 
\n `ProductID` int(11) NOT NULL, 
\n `InvoiceID` int(11) NOT NULL, 
\n `TravelDate` varchar(255) DEFAULT NULL, 
\n `TicketNote` varchar(255) DEFAULT NULL, 
\n `Quantity` int(11) DEFAULT NULL, 
\n `InsuranceTicketCode` varchar(255) DEFAULT NULL, 
\n PRIMARY KEY (`ProductInvoiceID`), 
\n KEY `fkPerson` (`PersonID`), 
\n KEY `fk_ProductInvoice_to_Product` (`ProductID`), 
\n KEY `fk_ProductInvoice_to_Invoice` (`InvoiceID`), 
\n CONSTRAINT `ProductInvoice_ibfk_1` FOREIGN KEY (`PersonID`) REFERENCES `Person` (`PersonID`), 
\n CONSTRAINT `ProductInvoice_ibfk_2` FOREIGN KEY (`ProductID`) REFERENCES `Product` (`ProductID`), 
\n CONSTRAINT `ProductInvoice_ibfk_3` FOREIGN KEY (`InvoiceID`) REFERENCES `Invoice` (`InvoiceID`) 
\n) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8' 
+0

Regardez ici comment trouver et supprimer la clé étrangère http://stackoverflow.com/a/19668812/1745672 – Mihai

+0

Afficher le résultat de 'SHOW CREATE TABLE ProductInvoice' – Mihai

+0

@Mihai J'ai édité le message principal –

Répondre

0

Goutte Foreign key première:

ALTER TABLE ProductInvoice DROP FOREIGN KEY ....; 

puis:

ALTER TABLE ProductInvoice DROP COLUMN PersonID; 
+0

J'ai essayé ceci comme bien et ça ne marchera pas. J'ai modifié le message d'origine pour inclure l'erreur. –

+0

@RyanDorman Vous devez utiliser le nom ** 'FOREIGN KEY' **. Non nom de la colonne – lad2025

+0

Cela fait un moment que j'ai écrit ces tableaux, y at-il un moyen de trouver cela facilement? –

1

d'abord désactiver les clés étrangères

SET foreign_key_checks = 0; 

Supprimer la clé sur PersonID

ALTER TABLE ProductInvoice 
    DROP INDEX fkPerson; 

laissent tomber la clé étrangère

ALTER TABLE ProductInvoice DROP FOREIGN KEY ProductInvoice_ibfk_1; 

déposer la colonne

ALTER TABLE ProductInvoice DROP COLUMN PersonID; 

Activer les clés étrangères:

SET foreign_key_checks = 1;