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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners