From 54665689edcf1d48af3b9408c5a8f922a16faf7d Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 30 Apr 2020 15:09:21 +0100 Subject: [PATCH] Fix compileDropDefaultConstraint was ignoring Table prefixes --- .../Database/Schema/Grammars/SqlServerGrammar.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php index d356e87cdead..f30be675939f 100755 --- a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php @@ -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;