Skip to content

Commit

Permalink
Avoid duplicate primary key error
Browse files Browse the repository at this point in the history
Signed-off-by: Sam <[email protected]>
  • Loading branch information
sampoyigi committed Mar 10, 2023
1 parent 1841f48 commit 4264b39
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class MakePageIdIncremental extends Migration
{
public function up()
{
$tablePrefix = Schema::getConnection()->getTablePrefix();
if (DB::select(DB::raw('SHOW KEYS FROM '.$tablePrefix.'pages WHERE Key_name=\'PRIMARY\' AND Column_name=\'page_id\'')))
return;

Schema::table('pages', function (Blueprint $table) {
$table->unsignedBigInteger('page_id', true)->change();
});
Expand Down

0 comments on commit 4264b39

Please sign in to comment.