setPayerNullability(false); } public function safeDown() { $table = '{{%APPROACH_DEC_ORDER}}'; $nullCount = (int) (new \yii\db\Query()) ->from($table) ->where(['USER_ID' => null]) ->count('*', $this->db); if ($nullCount > 0) { throw new \RuntimeException('Cannot restore APPROACH_DEC_ORDER.USER_ID NOT NULL while guest declaration rows exist.'); } $this->setPayerNullability(true); } private function setPayerNullability(bool $notNull): void { $table = '{{%APPROACH_DEC_ORDER}}'; $schema = $this->db->getTableSchema($table, true); if (!$schema || !isset($schema->columns['USER_ID'])) { throw new \RuntimeException('APPROACH_DEC_ORDER.USER_ID column was not found.'); } $column = $schema->columns['USER_ID']; if ((bool) $column->allowNull === !$notNull) { return; } $definition = $this->db->getSchema()->createColumnSchemaBuilder($column->type, $column->size); $definition->notNull($notNull); $this->alterColumn($table, 'USER_ID', $definition); } }