Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PrimaryKeyCanBeCreated.php
Go to the documentation of this file.
1 <?php
7 
11 
18 {
22  const ERROR_TYPE = 'primary_key_cant_be_applied';
23 
27  const ERROR_MESSAGE = 'Primary key can`t be applied on table "%s". ';
28 
32  public function validate(Schema $schema)
33  {
34  $errors = [];
35  foreach ($schema->getTables() as $table) {
36  $primaryConstraint = $table->getPrimaryConstraint();
37 
38  if (!$primaryConstraint) {
39  continue;
40  }
41 
42  foreach ($primaryConstraint->getColumns() as $column) {
43  if ($column instanceof ColumnNullableAwareInterface &&
44  $column->isNullable()
45  ) {
46  $errors[] = [
47  'column' => $column->getName(),
48  'message' => sprintf(self::ERROR_MESSAGE, $table->getName()) .
49  "All columns should be not nullable"
50  ];
51  }
52  }
53  }
54 
55  return $errors;
56  }
57 }
$table
Definition: trigger.php:14
$errors
Definition: overview.phtml:9