Skip to content

Commit

Permalink
Fix dropping columns with default value. Select only rows where defau…
Browse files Browse the repository at this point in the history
…lt_object_id is not 0. (#31341)

Co-authored-by: YaroslavMokhurenko <40685592+yaroslavmo@users.noreply.github.com>
  • Loading branch information
yarik3351 and yaroslavmo committed Feb 4, 2020
1 parent 5f4e862 commit 1f9bb9c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Schema/Grammars/SqlServerGrammar.php
Expand Up @@ -211,7 +211,7 @@ public function compileDropDefaultConstraint(Blueprint $blueprint, Fluent $comma
$sql = "DECLARE @sql NVARCHAR(MAX) = '';";
$sql .= "SELECT @sql += 'ALTER TABLE [dbo].[{$blueprint->getTable()}] DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' ";
$sql .= 'FROM SYS.COLUMNS ';
$sql .= "WHERE [object_id] = OBJECT_ID('[dbo].[{$blueprint->getTable()}]') AND [name] in ({$columns});";
$sql .= "WHERE [object_id] = OBJECT_ID('[dbo].[{$blueprint->getTable()}]') AND [name] in ({$columns}) AND [default_object_id] <> 0;";
$sql .= 'EXEC(@sql)';

return $sql;
Expand Down

0 comments on commit 1f9bb9c

Please sign in to comment.