xxxxxxxxxx
// Searched, laravel drop foreign column
Schema::table('users', function (Blueprint $table) {
$table->dropColumn(['votes', 'avatar', 'location']);
});
xxxxxxxxxx
Schema::table('posts', function (Blueprint $table) {
$table->dropForeign(['category_id']);
});
xxxxxxxxxx
public function down()
{
Schema::table('tarefas', function (Blueprint $table) {
$table->dropForeign('tarefas_user_id_foreign');
$table->dropColumn('user_id');
});
}
xxxxxxxxxx
Class RemoveCommentViewCount extends Migration
{
public function up()
{
Schema::table('articles', function($table) {
$table->dropColumn('comment_count');
$table->dropColumn('view_count');
});
}
public function down()
{
Schema::table('articles', function($table) {
$table->integer('comment_count');
$table->integer('view_count');
});
}
}
xxxxxxxxxx
// Primary table name, from Schema::table(<table>)
// Primary column, from $table->foreign(<column>)
$table->dropForeign('<table>_<column>_foreign');
xxxxxxxxxx
public function up()
{
Schema::table('your_table_name', function (Blueprint $table) {
// Drop foreign key constraint
$table->dropForeign(['your_foreign_key']);
});
}
xxxxxxxxxx
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class DropColumnFromTable extends Migration
{
/**
* Run the migration.
*
* @return void
*/
public function up()
{
Schema::table('table_name', function (Blueprint $table) {
$table->dropColumn('column_name');
});
}
/**
* Reverse the migration (rollback).
*
* @return void
*/
public function down()
{
Schema::table('table_name', function (Blueprint $table) {
$table->addColumn('data_type', 'column_name')->nullable();
});
}
}