diff --git a/src/Phinx/Db/Adapter/MysqlAdapter.php b/src/Phinx/Db/Adapter/MysqlAdapter.php index 8a767a74b..ffe014c20 100644 --- a/src/Phinx/Db/Adapter/MysqlAdapter.php +++ b/src/Phinx/Db/Adapter/MysqlAdapter.php @@ -1364,7 +1364,7 @@ protected function getColumnSqlDefinition(Column $column): string } if ($column->getPrecision() && $column->getScale() !== null) { $def .= '(' . $column->getPrecision() . ',' . $column->getScale() . ')'; - } elseif (isset($sqlType['limit'])) { + } elseif (($column->getLimit() !== null || !$column->hasLimitSet()) && isset($sqlType['limit'])) { $def .= '(' . $sqlType['limit'] . ')'; } diff --git a/src/Phinx/Db/Adapter/PostgresAdapter.php b/src/Phinx/Db/Adapter/PostgresAdapter.php index 9dc0fe431..fc0ac1eb5 100644 --- a/src/Phinx/Db/Adapter/PostgresAdapter.php +++ b/src/Phinx/Db/Adapter/PostgresAdapter.php @@ -1280,7 +1280,7 @@ protected function getColumnSqlDefinition(Column $column): string self::PHINX_TYPE_BINARY, ], true) ) { - if ($column->getLimit() || isset($sqlType['limit'])) { + if ($column->getLimit() || (!$column->hasLimitSet() && isset($sqlType['limit']))) { $buffer[] = sprintf('(%s)', $column->getLimit() ?: $sqlType['limit']); } } diff --git a/src/Phinx/Db/Adapter/SQLiteAdapter.php b/src/Phinx/Db/Adapter/SQLiteAdapter.php index fe622177f..fb635ac8a 100644 --- a/src/Phinx/Db/Adapter/SQLiteAdapter.php +++ b/src/Phinx/Db/Adapter/SQLiteAdapter.php @@ -1864,7 +1864,7 @@ protected function getColumnSqlDefinition(Column $column): string $def = strtoupper($sqlType['name']); $limitable = in_array(strtoupper($sqlType['name']), $this->definitionsWithLimits, true); - if (($column->getLimit() || isset($sqlType['limit'])) && $limitable) { + if (($column->getLimit() || (!$column->hasLimitSet() && isset($sqlType['limit']))) && $limitable) { $def .= '(' . ($column->getLimit() ?: $sqlType['limit']) . ')'; } } diff --git a/src/Phinx/Db/Adapter/SqlServerAdapter.php b/src/Phinx/Db/Adapter/SqlServerAdapter.php index 6a36f81cd..a64044530 100644 --- a/src/Phinx/Db/Adapter/SqlServerAdapter.php +++ b/src/Phinx/Db/Adapter/SqlServerAdapter.php @@ -1250,7 +1250,7 @@ protected function getColumnSqlDefinition(Column $column, bool $create = true): $column->getPrecision() ?: $sqlType['precision'], $column->getScale() ?: $sqlType['scale'], ); - } elseif (!in_array($sqlType['name'], $noLimits) && ($column->getLimit() || isset($sqlType['limit']))) { + } elseif (!in_array($sqlType['name'], $noLimits) && ($column->getLimit() || (!$column->hasLimitSet() && isset($sqlType['limit'])))) { $buffer[] = sprintf('(%s)', $column->getLimit() ?: $sqlType['limit']); } } diff --git a/src/Phinx/Db/Table/Column.php b/src/Phinx/Db/Table/Column.php index 3941f037e..21ac3379a 100644 --- a/src/Phinx/Db/Table/Column.php +++ b/src/Phinx/Db/Table/Column.php @@ -75,6 +75,11 @@ class Column */ protected ?int $limit = null; + /** + * @var bool + */ + protected bool $limitSet = false; + /** * @var bool */ @@ -229,6 +234,7 @@ public function getType(): string|Literal public function setLimit(?int $limit) { $this->limit = $limit; + $this->limitSet = true; return $this; } @@ -243,6 +249,11 @@ public function getLimit(): ?int return $this->limit; } + public function hasLimitSet(): bool + { + return $this->limitSet; + } + /** * Sets whether the column allows nulls. *