I did a mistake while creating the laravel migration file. Added ON DELETE cascade in the foreign key and made the column not nullable.
This will be the query to drop the foreign key: ALTER TABLE posts DROP FOREIGN KEY posts_category_id_foreign; ALTER TABLE posts DROP COLUMN category_id; Enter fullscreen mode
Now let's see how we convert this in migration: First create the migration file php artisan make:migration update_posts_category_foreign
Schema::table('posts', function (Blueprint $table) { $table->dropForeign('posts_category_id_foreign'); $table->dropColumn('category_id'); }); Now as the column is removed we can now add the nullable column and new foreign key