Skip to content

Commit

Permalink
Revert "[10.x] Drop the primary key if it exists when adding a new pr…
Browse files Browse the repository at this point in the history
…imary key (#49392)" (#49448)

This reverts commit be24812.
  • Loading branch information
taylorotwell committed Dec 20, 2023
1 parent b0ed9e1 commit cec9e98
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Expand Up @@ -406,7 +406,7 @@ public function compileChange(Blueprint $blueprint, Fluent $command, Connection
*/
public function compilePrimary(Blueprint $blueprint, Fluent $command)
{
return sprintf('alter table %s drop index if exists `PRIMARY`, add primary key %s(%s)',
return sprintf('alter table %s add primary key %s(%s)',
$this->wrapTable($blueprint),
$command->algorithm ? 'using '.$command->algorithm : '',
$this->columnize($command->columns)
Expand Down
4 changes: 2 additions & 2 deletions tests/Database/DatabaseMySqlSchemaGrammarTest.php
Expand Up @@ -345,7 +345,7 @@ public function testAddingPrimaryKey()
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertSame('alter table `users` drop index if exists `PRIMARY`, add primary key (`foo`)', $statements[0]);
$this->assertSame('alter table `users` add primary key (`foo`)', $statements[0]);
}

public function testAddingPrimaryKeyWithAlgorithm()
Expand All @@ -355,7 +355,7 @@ public function testAddingPrimaryKeyWithAlgorithm()
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertSame('alter table `users` drop index if exists `PRIMARY`, add primary key using hash(`foo`)', $statements[0]);
$this->assertSame('alter table `users` add primary key using hash(`foo`)', $statements[0]);
}

public function testAddingUniqueKey()
Expand Down

0 comments on commit cec9e98

Please sign in to comment.