0

This has bothered me for awhile. The way I've been renaming columns that have foreign keys thus far has been to first remove all the foreign key constraints on various tables, and their indexes... then I rename the column, then I re-add all the indexes and foreign keys on all the tables I removed.

This is very time-consuming... especially if I have tons of foreign keys to drop and re-add because it is being used in many tables in the database. Creating the migration files for these to run against the production database takes forever, and I gotta think there must be a way for mysql to be smarter than this.

Is there a simpler way? I need to maintain my data.

Kara
  • 6,115
  • 16
  • 50
  • 57
egervari
  • 22,372
  • 32
  • 121
  • 175
  • Why do you have to keep renaming the columns? – dave Dec 11 '11 at 17:59
  • @dave because I'm refactoring a product to be very different than it was originally intended. The names and even the structure of things are changing like crazy. – egervari Dec 11 '11 at 18:00

1 Answers1

1

You can rename the fields with dependency check with a dbForge Studio for MySQL (get Cristmas discounts - 20% off, or try Express version ;-). I cannot say the it will be faster, but it will help you to rename these fields and recreate keys automatically in a few steps - just change its name in a Database Explorer and click on Refactor button in message box.

Devart
  • 119,203
  • 23
  • 166
  • 186
  • 1
    I figured something like this has to exist. It seems like a rather mechanical process. It is a shame that MySQL itself is not smart enough to do this and one would need an external product to generate these migrations on your behalf. Makes sense though. – egervari Dec 12 '11 at 14:24