mysql modifier int colonne bigint avec les clés étrangères

Je veux changer le type de données de certaines colonnes clés primaires dans ma base de données à partir de INT de type BIGINT. La définition suivante est un jouet-exemple pour illustrer le problème:

CREATE TABLE IF NOT EXISTS `owner` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `thing_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `thing_id` (`thing_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

DROP TABLE IF EXISTS `thing`;
CREATE TABLE IF NOT EXISTS `thing` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

ALTER TABLE `owner`
  ADD CONSTRAINT `owner_ibfk_1` FOREIGN KEY (`thing_id`) REFERENCES `thing` (`id`);

Maintenant quand j'essaye de execut l'une des commandes suivantes:

ALTER TABLE `thing` CHANGE `id` `id` BIGINT NOT NULL AUTO_INCREMENT;
ALTER TABLE `owner` CHANGE `thing_id` `thing_id` BIGINT NOT NULL;

je suis en cours d'exécution dans une erreur

#1025 - Error on rename of './debug/#[temp-name]' to './debug/[tablename]' (errno: 150)

MONTRER INODB sorties d'ÉTAT:

LATEST FOREIGN KEY ERROR
------------------------
120126 13:34:03 Error in foreign key constraint of table debug/owner:
there is no index in the table which would contain
the columns as the first columns, or the data types in the
table do not match the ones in the referenced table
or one of the ON ... SET NULL columns is declared NOT NULL. Constraint:
,
 CONSTRAINT "owner_ibfk_1" FOREIGN KEY ("thing_id") REFERENCES "thing" ("id")

Je suppose que la clé étrangère de définition de blocs de changer le type de colonne de chaque côté. L'approche naïve pour résoudre ce problème serait de supprimer les définitions des clés étrangères, modifier le nombre de colonnes et de re-définir les clés étrangères. est-il une meilleure solution?

L'approche que vous avez mentionné n'est pas naïf, vous pouvez vraiment l'utiliser.
Grâce Devart! J'étais à la recherche d'un douloureux solution, car j'ai pour elle sur beaucoup de tables, mais, apparemment, de supprimer et de recréer des contraintes semble être la voie à suivre :-/.

OriginalL'auteur deif | 2012-01-26