function SchemaDefinitionTest::testInvalidPrimaryKeyForGeneratedColumn

Same name and namespace in other branches
  1. main 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 243

Class

SchemaDefinitionTest
Tests SchemaDefinition Column object validations.

Namespace

Drupal\Tests\Core\Database

Code

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.