Jump to content

test pour supprimer une foreign key à la désinstallation d'un module


Recommended Posts

Bonjour,

J'essaye de créer un module avec une foreign key. Donc si je desinstalle le module, je veux supprimer la foreign key.

$query = "SELECT COUNT(*) FROM information_schema.columns WHERE table_name = 'ps_product_attribute_shop' AND column_name = 'id_wineos_attribute'";
$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->Execute($query);

if( $results != 0 ){

    $sql[] = "SET SQL_MODE='ALLOW_INVALID_DATES'";

    $sql[] = 'ALTER TABLE `' . _DB_PREFIX_ . 'product_attribute_shop`
      ADD `id_wineos_attribute` INT(11) NULL,
      ADD CONSTRAINT `fk_id_wineos_attribute` FOREIGN KEY (`id_wineos_attribute`) REFERENCES `' . _DB_PREFIX_ . 'wineos_attribute`(`id_wineos_attribute`)';
  }

Alors que la foreign key n'existe pas, à la reinitialisation du module, cela me met :

 

Error!
Exception retournée par le module wineos_attribute pour reset. Erreur lors de la réinitialisation du module wineos_attribute. Can't DROP 'fk_id_wineos_attribute'; check that column/key exists
 
ALTER TABLE `ps_product_attribute_shop`
    DROP FOREIGN KEY `fk_id_wineos_attribute`

 

Je ne comprends pas...merci de votre aide.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...