Open Justin-Barker opened 6 years ago
I reviewed the DB driver migrations and merged into one for a work around.
Migration can not be combined. It breaks extension updating.
What is DF_qu_prior_
object that is dependent on priority
column?
It is from ../src/drivers/db/migrations/M...Priority.php:
public function up()
{
$this->addColumn($this->tableName, 'priority', $this->integer()->unsigned()->notNull()->defaultValue(1024)->after('delay'));
$this->createIndex('priority', $this->tableName, 'priority');
}
The migration includes priority
column and priority
index creating. What is DF_qu_prior_
object? Is it special mssql object?
I don't have experience with mssql. I need more info about.
I am not well versed in MSSQL inner component handling, but from what I am able to discern is that tables will create a constraint object that defines anything from column definitions such as NOT NULL to indices. Therefore, it appears the index must be removed prior to column rollback. This will appear under the table's Constraints folder within MS SQL Studio. See below...
[Edited: add more detailed screenshots]
SQL Server Developer Edition can be downloaded for free here.
In MSSQL when we use ->defaultValue('xxx')
it add a autogenerated CONSTRAINT named DB__xxxx.
To drop those columns in migrations, we should drop the constraint before the column.
Because the name is autogenerated, you should find the name it db sys table.
To do that, I added a method in our Migration base:
/**
* Builds and executes a SQL statement for dropping a column default constraint.
*
* @param string $table the table whose column is to be altered. The name will be properly quoted by the method.
* @param string $column the name of the column to be altered. The name will be properly quoted by the method.
*/
public function dropDefaultConstraint($table, $column)
{
echo " > drop default value constraint for column $column from table $table ...";
$time = microtime(true);
$constraint = (new Query())
->select(['default_constraints.name'])
->from('sys.default_constraints')
->innerJoin('sys.all_columns', 'default_constraints.object_id = all_columns.default_object_id')
->innerJoin('sys.tables', 'tables.object_id = all_columns.object_id')
->innerJoin('sys.schemas', 'schemas.schema_id = tables.schema_id')
->where(
[
'AND',
['schemas.name' => 'dbo'],
['tables.name' => $this->db->schema->getRawTableName($table)],
['all_columns.name' => $column],
]
)
->scalar($this->db);
if (!empty($constraint)) {
$this->db->createCommand()->dropForeignKey($constraint, $table)->execute();
}
echo ' done (time: '.sprintf('%.3f', microtime(true) - $time)."s)\n";
}
I have been able to consistently reproduce this error within SQL Server 2012.
Steps: