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 <[email protected]>
  • Loading branch information
yarik3351 and yaroslavmo authored Feb 4, 2020
1 parent 43de546 commit 333b501
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
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 333b501

Please sign in to comment.