function SchemaDefinitionTest::testInvalidPrimaryKeyForGeneratedColumn
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/Core/Database/SchemaDefinitionTest.php \Drupal\Tests\Core\Database\SchemaDefinitionTest::testInvalidPrimaryKeyForGeneratedColumn()
Tests that a generated column cannot be part of the primary key.
File
-
core/
tests/ Drupal/ Tests/ Core/ Database/ SchemaDefinitionTest.php, line 245
Class
- SchemaDefinitionTest
- Tests SchemaDefinition Column object validations.
Namespace
Drupal\Tests\Core\DatabaseCode
public function testInvalidPrimaryKeyForGeneratedColumn() : void {
$this->expectException(SchemaDefinitionException::class);
$this->expectExceptionMessage("The primary key of the 'test' Table cannot include generated columns");
new Table(name: 'test', columns: [
Column::create(name: 'age', type: ColumnType::Int),
Column::generated(name: 'double_age', type: ColumnType::Int, expression: new GeneratedColumnExpression('[age] * 2'), storage: GeneratedColumnStorage::Stored),
], primaryKey: new PrimaryKey([
'double_age',
]));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.