diff --git a/src/Sql/Ddl/Column/Column.php b/src/Sql/Ddl/Column/Column.php index dac7bda4..42c42770 100644 --- a/src/Sql/Ddl/Column/Column.php +++ b/src/Sql/Ddl/Column/Column.php @@ -115,6 +115,8 @@ public function getExpressionData(): array if ($this->isNullable === false) { $specParts[] = 'NOT NULL'; + } else { + $specParts[] = 'NULL'; } if ($this->default !== null) { @@ -122,6 +124,8 @@ public function getExpressionData(): array $values[] = $this->default instanceof ArgumentInterface ? $this->default : new Value($this->default); + } elseif ($this->isNullable) { + $specParts[] = 'DEFAULT NULL'; } foreach ($this->constraints as $constraint) { diff --git a/test/unit/Sql/Ddl/Column/ColumnTest.php b/test/unit/Sql/Ddl/Column/ColumnTest.php index 9b9e9f76..d32556e6 100644 --- a/test/unit/Sql/Ddl/Column/ColumnTest.php +++ b/test/unit/Sql/Ddl/Column/ColumnTest.php @@ -151,7 +151,7 @@ public function testGetExpressionData(): void $expressionData = $column->getExpressionData(); - self::assertEquals('%s %s', $expressionData['spec']); + self::assertEquals('%s %s NULL DEFAULT NULL', $expressionData['spec']); self::assertEquals([ Argument::identifier('foo'), Argument::literal('INTEGER'), @@ -161,7 +161,7 @@ public function testGetExpressionData(): void $expressionData = $column->getExpressionData(); - self::assertEquals('%s %s DEFAULT %s', $expressionData['spec']); + self::assertEquals('%s %s NULL DEFAULT %s', $expressionData['spec']); self::assertEquals([ Argument::identifier('foo'), Argument::literal('INTEGER'),