Description
Q | A |
---|---|
Version | 4.2.x |
SQLite doesn't support auto-increment columns as part of composite primary key. An auto-increment column should be declared either as INTEGER PRIMARY KEY
or INTEGER PRIMARY KEY AUTOINCREMENT
(documentation).
When building the table DDL, if there is an auto-increment column, when building the table DDL, will silently ignore other primary key columns:
$table = new Table('test_autoincrement');
$table->addColumn('id1', Types::INTEGER, ['autoincrement' => true]);
$table->addColumn('id2', Types::INTEGER);
$table->setPrimaryKey(['id1', 'id2']);
$this->dropAndCreateTable($table);
$table = $this->schemaManager->introspectTable('test_autoincrement');
var_dump($table->getIndex('primary')->getColumns());
// array(1) {
// [0]=>
// string(3) "id1"
// }
Instead, it shouldn't allow such a table to be created.
Additionally, similar to #6840 (but the other way around) DBAL silently creates primary key if a column is auto-increment:
$table = new Table('test_autoincrement');
$table->addColumn('id', Types::INTEGER, ['autoincrement' => true]);
$this->dropAndCreateTable($table);
$table = $this->schemaManager->introspectTable('test_autoincrement');
var_dump($table->getIndex('primary')->getColumns());
// array(1) {
// [0]=>
// string(3) "id"
// }
Similarly to the first case, it shouldn't allow such a table to be created.