Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save diegoglz-dev/3002e337557ed14136e7f0eb4007bfc6 to your computer and use it in GitHub Desktop.

Select an option

Save diegoglz-dev/3002e337557ed14136e7f0eb4007bfc6 to your computer and use it in GitHub Desktop.
Add and drop foreign key in migration on production.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('customer_orders', function (Blueprint $table) {
$table->decimal('price', 9, 2)->default(0)->after('deadline');
$table->decimal('min_price', 9, 2)->default(0)->after('price')->nullable();
$table->foreignId('order_id')->after('min_price')->nullable()->constrained()->cascadeOnDelete();
$table->text('observation')->after('order_id')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('customer_orders', function (Blueprint $table) {
$table->dropColumn(['price', 'min_price', 'observation']);
$table->dropForeign(['order_id']);
$table->dropColumn('order_id');
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment