Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
prabhu pandurangan
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48952
60
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Campbell
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • 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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic