
Drop foreign key column in Laravel using migration
You can drop foreign key column with constraints in Laravel using migration, you have to create migration file and add dropForeign() and dropColumn() method inside up or down function in migration file and run migration command to drop the column.
-
Drop foreign key constraint posts_user_id_foreign from posts table with column in Laravel using migration
--PATH database\migrations\<2021_11_15_101237_drop_posts_user_id_foreign_from_posts>.phppublic function up(){ Schema::table('posts', function(Blueprint $table){ $table->dropForeign('posts_user_id_foreign'); $table->dropColumn('user_id'); }); }
0To get the foreign key constraint, click on table in the specific database and click on relation view after click on structure of the table.
Create migration file using php artisan make:migration drop_posts_user_id_foreign_from_posts --table=posts command.
Add the foreign key constraint to the dropForeign method which you want to drop and run migration command to drop the column and foreign key constraint.
-
Drop foreign key constraint with index and column in Laravel using migration
--PATH database\migrations\<2021_11_15_101237_drop_posts_user_id_foreign_from_posts>.phppublic function up(){ Schema::table('posts', function(Blueprint $table){ $table->dropForeign('posts_user_id_foreign'); $table->dropIndex('posts_user_id_foreign'); $table->dropColumn('user_id'); }); }
0Using this code snippet you can drop foreign key column with index and constraint name in Laravel.
To get the foreign key constraint, click on table in the specific database and click on relation view after click on structure of the table.
Create migration file using php artisan make:migration drop_posts_user_id_foreign_from_posts --table=posts command.
Add the foreign key constraint to the dropForeign method which you want to drop and run migration command to drop the column and foreign key constraint.
Random Code Snippet Queries: Laravel
- Method Illuminate\Database\Eloquent\Collection::appends does not exist
- How to create and run user seeder in laravel
- Laravel URL validation not working
- Create project factory and seed data in laravel
- Get current month records in laravel 7/8
- How to check record exist or not in relationship table
- How to get route method name in Laravel
- Get domain name in laravel
- Return view from route Laravel
- Send OTP using textlocal api in laravel
- Laravel upload file with original file name
- How to generate .env file for laravel?
- How to get IP address in laravel
- How to update record after save method in Laravel
- How to increment column value of table in Laravel
- Method Illuminate\Http\Request::validated does not exist
- Display success message in laravel
- Class 'App\Http\Controllers\User' not found
- Add [name] to fillable property to allow mass assignment on [App\Models\Project]
- Recursive function example code PHP Laravel
- Generate unique username in Laravel
- How to check duplicate entry in laravel
- Remove several global scope from query
- Method Illuminate\Events\Dispatcher::fire does not exist
- Generate random string lowercase in Laravel