You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have discovered a bug that occurs when using Phinx with MariaDB, and trying to update a TIMESTAMP column with current_timestamp() as default value.
The error:PDOException: SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'createdAt'
We have found the reason the error occurs. MariaDB is defaulting the TIMESTAMP-value to current_timestamp() in lower-case. There is Phinx code to NOT quote CURRENT_TIMESTAMP in src/Phinx/Db/Adapter/PdoAdapter.php:getDefaultValueDefinition(), but because it only handles upper-case, this lower-case default value is quoted anyway.
elseif (is_string($default) && strpos($default, 'CURRENT_TIMESTAMP') !== 0) {
// Ensure a defaults of CURRENT_TIMESTAMP(3) is not quoted.
$default = $this->getConnection()->quote($default);
}
The suggested fix: Adding strtolower around $default and 'CURRENT_TIMESTAMP' in src/Phinx/Db/Adapter/PdoAdapter.php:getDefaultValueDefinition().
} elseif (is_string($default) && strpos(strtolower($default), strtolower('CURRENT_TIMESTAMP')) !== 0) {
// Ensure a defaults of CURRENT_TIMESTAMP(3) is not quoted.
$default = $this->getConnection()->quote($default);
}
Is it possible to get this small fix done? :-) Or is there another workaround?
Thanks for your reply. I'll look into doing a pull request.
In the meantime, we managed to solve it by creating a custom adapter and doing the necessary change of the default value, before calling the original getDefaultValueDefinition() function.
Maybe the solution in here would be for phinx to not quote functions.
In this case someone might want to use the functionality of precision described in here https://mariadb.com/kb/en/current_timestamp/
We have discovered a bug that occurs when using Phinx with MariaDB, and trying to update a TIMESTAMP column with
current_timestamp()
as default value.The error:
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'createdAt'
We have found the reason the error occurs. MariaDB is defaulting the TIMESTAMP-value to current_timestamp() in lower-case. There is Phinx code to NOT quote CURRENT_TIMESTAMP in
src/Phinx/Db/Adapter/PdoAdapter.php:getDefaultValueDefinition()
, but because it only handles upper-case, this lower-case default value is quoted anyway.The suggested fix: Adding strtolower around $default and 'CURRENT_TIMESTAMP' in
src/Phinx/Db/Adapter/PdoAdapter.php:getDefaultValueDefinition()
.Is it possible to get this small fix done? :-) Or is there another workaround?
Apparently, MariaDB has changed the default from CURRENT_TIMESTAMP to current_timestamp() from version 10.2.3. (https://mariadb.com/kb/en/now/#description )
Our migration causing the error:
The generated SQL causing the error:
The text was updated successfully, but these errors were encountered: