
Drop foreign key column in Laravel using migration
Drop foreign key column in Laravel using migration
We’ll attempt to use programming in this lesson to solve the "Drop foreign key column in Laravel using migration" puzzle.
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'); }); }
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.
-
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'); }); }
Using 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.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Trying to access array offset on value of type null error in laravel
- Get all users except the followings users in overtrue laravel-follow
- How to get path from current URL in Laravel
- Display data in table using foreach in Laravel
- How to check if user has created any post or not in laravel
- Laravel create default admin user
- How to check record exist or not in relationship table
- Laravel URL validation not working
- Permanently delete a record in laravel
- How to create new user without form submission in laravel
- Print last executed query in laravel
- Comment .env file in laravel
- Session Doesn't Work on Redirect
- Class "App\Http\Controllers\Auth\Verified" not found
- Route prefix with auth middleware in laravel
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- Shorter syntax for whereHas with call back function in laravel
- Class 'App\Rules\Hash' not found in Laravel
- Get comma separated email from input array
- Datetime field in Laravel migration
- Return redirect laravel not working
- How to get route name on visit URL in laravel
- Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
- PhpMyAdmin - Error The mysqli extension is missing
- How to pass data to multiple partial view files in laravel