'delete a table form a database using laravel command
i need to delete a database table using laravel artisan command . not like this command php artisan migrate:rollback --step=5
i need to create like this route or controller code .
Route::get('/clear/database', function () {
Artisan::call('cache:clear');
return redirect('/');
});
. i also try public function dd()
{
Schema::drop('table_name');
}
but it not working . gives me error like this SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (SQL: drop table table_name)
no foreign key for the table . what should i do ?
thanks in advance!
Solution 1:[1]
it's because one of your tables has a fk that is pointing to the table you are trying to delete
use Illuminate\Support\Facades\DB;
DB::statement('SET FOREIGN_KEY_CHECKS = 0');
Schema::dropIfExists('table');
// or
Artisan::call('command');
DB::statement('SET FOREIGN_KEY_CHECKS = 1');
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
