Drop foreign id column (user_id) in MySQL

You can drop the foreign id column user_id in MySQL. You have to first delete the foreign key and index before deleting the foreign id column else it will give error #1553 - Cannot drop index 'posts_user_id_foreign': needed in a foreign key constraint.

Answers 1
  • Drop column (foreign Id) user_id from posts table

    ALTER TABLE `posts` DROP COLUMN `user_id`;
    
    0

    You can drop column user_id from posts table using drop column method in MySQL. If you are getting error #1553 Cannot drop index 'posts_user_id_foreign': needed in a foreign key constraint then you have to first delete the foreign key and indexes.

  • Back to code snippet queries related sql

Related queries helps you to understand and may also used for implementation of current code snippet