FIX: Check index exists before dropping

This commit is contained in:
Will Rossiter 2016-07-13 14:47:38 +12:00
parent a3931654b7
commit 2e64e44087

View File

@ -395,8 +395,9 @@ class MSSQLSchemaManager extends DBSchemaManager
// drop *ALL* indexes on a table before proceeding // drop *ALL* indexes on a table before proceeding
// this won't drop primary keys, though // this won't drop primary keys, though
$indexes = $this->indexNames($tableName); $indexes = $this->indexNames($tableName);
foreach ($indexes as $indexName) { foreach ($indexes as $indexName) {
$alterQueries[] = "DROP INDEX \"$indexName\" ON \"$tableName\";"; $alterQueries[] = "\nIF EXISTS (SELECT name FROM sys.indexes WHERE name = '$indexName' AND object_id = object_id('schema.$tableName')) DROP INDEX \"$indexName\" ON \"$tableName\";";
} }
$prefix = "ALTER TABLE \"$tableName\" "; $prefix = "ALTER TABLE \"$tableName\" ";