xxxxxxxxxx
Schema::drop('users');
Schema::dropIfExists('users');
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
//Get all the table names
$all_table_names = Schema::getConnection()->getDoctrineSchemaManager()->listTableNames();
foreach ($all_table_names as $name) {
//if you don't want to truncate migrations in Database
if ($name == 'migrations') {
continue;
}
DB::table($name)->truncate();
}
xxxxxxxxxx
foreach(\DB::select('SHOW TABLES') as $table) {
$all_table_names = get_object_vars($table);
\Schema::drop($all_table_names[key($all_table_names)]);
}
xxxxxxxxxx
// delete a migration safely from laravel
delete migration from database/migrations/ directory
and also delete entry from migrations table
xxxxxxxxxx
Comment::where('post_id',$id)->delete();
// in down migration
public function down()
{
Schema::table('package_types', function (Blueprint $table) {
\App\Models\PackageType::query()->where('id','gt',1)->delete();
});
}
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();
});
}
}