• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to drop a foreign_key column from a table also with data that is existing, Mysql?

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Members,

I have to delete a column from a table, which is a foreign_key. Also the column has some data with it. I need to drop the column along with the data.
Im using mysql 5.0.27.

Please share your views in this. How it shall be done.

I also tried using 'set foreign_key_checks = 0;' But im facing some exceptions:

Error: 150, error on rename.

Regards,
Prabhu.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it is a foreign key, you are supposed to keep the data, particularly if it is labelled ON DELETE RESTRICT. You would have to drop all tables using that column first, before dropping the column.
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


or



If it still is an issue and it is because your foreign key is also a key in the table, too:



If that doesn't work... you will need to do what Campbell suggests... but you will need to unload your table and reload it after removing your column(s).
 
reply
    Bookmark Topic Watch Topic
  • New Topic