Created
March 25, 2024 01:04
-
-
Save ryantxr/70c969a33c6cc23ca824b87f4a56e213 to your computer and use it in GitHub Desktop.
Laravel migration mod to turn off primary key requirement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Migrations\Migration; | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Support\Facades\Schema; | |
use Illuminate\Support\Facades\DB; | |
return new class extends Migration | |
{ | |
/** | |
* Run the migrations. | |
*/ | |
public function up(): void | |
{ | |
$originalSetting = DB::select("SHOW SESSION VARIABLES LIKE 'sql_require_primary_key'")[0]->Value; | |
// Turn off if necessary | |
if ($originalSetting == 'ON') { | |
DB::statement('SET SESSION sql_require_primary_key=0'); | |
} | |
Schema::create('password_reset_tokens', function (Blueprint $table) { | |
$table->string('email')->primary(); | |
$table->string('token'); | |
$table->timestamp('created_at')->nullable(); | |
}); | |
if ($originalSetting == 'ON') { | |
DB::statement('SET SESSION sql_require_primary_key=1'); | |
} | |
} | |
/** | |
* Reverse the migrations. | |
*/ | |
public function down(): void | |
{ | |
Schema::dropIfExists('password_reset_tokens'); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment