| @@ 7-34 (lines=28) @@ | ||
| 4 | use Illuminate\Database\Schema\Blueprint; |
|
| 5 | use Illuminate\Support\Facades\Schema; |
|
| 6 | ||
| 7 | class ChangeForeignKeyForParentCategories extends Migration |
|
| 8 | { |
|
| 9 | /** |
|
| 10 | * Run the migrations. |
|
| 11 | * |
|
| 12 | * @return void |
|
| 13 | */ |
|
| 14 | public function up() |
|
| 15 | { |
|
| 16 | Schema::table('categories', function (Blueprint $table) { |
|
| 17 | $table->dropForeign(['parent_id']); |
|
| 18 | $table->foreign('parent_id')->references('id')->on('categories')->onDelete('cascade'); |
|
| 19 | }); |
|
| 20 | } |
|
| 21 | ||
| 22 | /** |
|
| 23 | * Reverse the migrations. |
|
| 24 | * |
|
| 25 | * @return void |
|
| 26 | */ |
|
| 27 | public function down() |
|
| 28 | { |
|
| 29 | Schema::table('categories', function (Blueprint $table) { |
|
| 30 | $table->dropForeign(['parent_id']); |
|
| 31 | $table->foreign('parent_id')->references('id')->on('categories'); |
|
| 32 | }); |
|
| 33 | } |
|
| 34 | } |
|
| 35 | ||
| @@ 7-34 (lines=28) @@ | ||
| 4 | use Illuminate\Database\Schema\Blueprint; |
|
| 5 | use Illuminate\Support\Facades\Schema; |
|
| 6 | ||
| 7 | class ChangeForeignKeyParentLastUsedCategoryOnPayeesTable extends Migration |
|
| 8 | { |
|
| 9 | /** |
|
| 10 | * Run the migrations. |
|
| 11 | * |
|
| 12 | * @return void |
|
| 13 | */ |
|
| 14 | public function up() |
|
| 15 | { |
|
| 16 | Schema::table('payees', function (Blueprint $table) { |
|
| 17 | $table->dropForeign(['last_category_id']); |
|
| 18 | $table->foreign('last_category_id')->references('id')->on('categories')->onDelete('set null'); |
|
| 19 | }); |
|
| 20 | } |
|
| 21 | ||
| 22 | /** |
|
| 23 | * Reverse the migrations. |
|
| 24 | * |
|
| 25 | * @return void |
|
| 26 | */ |
|
| 27 | public function down() |
|
| 28 | { |
|
| 29 | Schema::table('payees', function (Blueprint $table) { |
|
| 30 | $table->dropForeign(['last_category_id']); |
|
| 31 | $table->foreign('last_category_id')->references('id')->on('categories'); |
|
| 32 | }); |
|
| 33 | } |
|
| 34 | } |
|
| 35 | ||