Skip to content

Commit

Permalink
Merge pull request #32606 from laravel/sql-fix
Browse files Browse the repository at this point in the history
[6.x] Fix compileDropDefaultConstraint was ignoring Table prefixes
  • Loading branch information
taylorotwell committed May 1, 2020
2 parents 48e4d60 + 5466568 commit 7f00dbb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,12 @@ public function compileDropDefaultConstraint(Blueprint $blueprint, Fluent $comma
{
$columns = "'".implode("','", $command->columns)."'";

$tableName = $this->getTablePrefix().$blueprint->getTable();

$sql = "DECLARE @sql NVARCHAR(MAX) = '';";
$sql .= "SELECT @sql += 'ALTER TABLE [dbo].[{$blueprint->getTable()}] DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' ";
$sql .= "SELECT @sql += 'ALTER TABLE [dbo].[{$tableName}] DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' ";
$sql .= 'FROM SYS.COLUMNS ';
$sql .= "WHERE [object_id] = OBJECT_ID('[dbo].[{$blueprint->getTable()}]') AND [name] in ({$columns}) AND [default_object_id] <> 0;";
$sql .= "WHERE [object_id] = OBJECT_ID('[dbo].[{$tableName}]') AND [name] in ({$columns}) AND [default_object_id] <> 0;";
$sql .= 'EXEC(@sql)';

return $sql;
Expand Down

0 comments on commit 7f00dbb

Please sign in to comment.