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
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners