Browse Source

! Postgresql fails in create non-null db columns [Topic 470906] - Thanks Tyris for the report

emanuele 13 years ago
parent
commit
4ae4f96c0f
1 changed files with 3 additions and 3 deletions
  1. 3 3
      Sources/DbPackages-postgresql.php

+ 3 - 3
Sources/DbPackages-postgresql.php

@@ -397,12 +397,12 @@ function smf_db_change_column($table_name, $old_column, $column_info, $parameter
 		$smcFunc['db_transaction']('begin');
 		if (!$column_info['null'])
 		{
-			// We have to set it to something if we are making it NOT NULL.
-			$setTo = isset($column_info['default']) ? $column_info['default'] : '';
+			// We have to set it to something if we are making it NOT NULL. And we must comply with the current column format.
+			$setTo = isset($column_info['default']) ? $column_info['default'] : (strpos($old_info['type'], 'int') !== false ? 0 : '');
 			$smcFunc['db_query']('', '
 				UPDATE ' . $table_name . '
 				SET ' . $column_info['name'] . ' = \'' . $setTo . '\'
-				WHERE ' . $column_info['name'] . ' = NULL',
+				WHERE ' . $column_info['name'] . ' IS NULL',
 				array(
 					'security_override' => true,
 				)