{"record":{"id":"1b73795ca19d5f6d","repo":"SonarSource/sonarqube","slug":"column-with-autoincrement-is-neither-biginteger-i","errorCode":null,"errorMessage":"Column with autoincrement is neither BigInteger, Integer, nor SmallInt","messagePattern":"Column with autoincrement is neither BigInteger, Integer, nor SmallInt","errorType":"exception","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilder.java","lineNumber":160,"sourceCode":"      appendDefaultValue(res, columnDef);\n      appendNullConstraint(res, columnDef);\n      appendColumnFlags(res, dialect, columnDef);\n      if (columnDefIterator.hasNext()) {\n        res.append(',');\n      }\n    }\n  }\n\n  private void appendDataType(StringBuilder res, Dialect dialect, ColumnDef columnDef) {\n    if (PostgreSql.ID.equals(dialect.getId()) && isAutoIncrement(columnDef)) {\n      if (columnDef instanceof BigIntegerColumnDef) {\n        res.append(\"BIGSERIAL\");\n      } else if (columnDef instanceof IntegerColumnDef) {\n        res.append(\"SERIAL\");\n      } else if (columnDef instanceof SmallIntColumnDef) {\n        res.append(\"SMALLSERIAL\");\n      } else {\n        throw new IllegalStateException(\"Column with autoincrement is neither BigInteger, Integer, nor SmallInt\");\n      }\n    } else {\n      res.append(columnDef.generateSqlType(dialect));\n    }\n  }\n\n  private boolean isAutoIncrement(ColumnDef columnDef) {\n    Collection<ColumnFlag> columnFlags = this.flagsByColumn.get(columnDef);\n    return columnFlags.contains(ColumnFlag.AUTO_INCREMENT);\n  }\n\n  private static void appendNullConstraint(StringBuilder res, ColumnDef columnDef) {\n    if (columnDef.isNullable()) {\n      res.append(\" NULL\");\n    } else {\n      res.append(\" NOT NULL\");\n    }\n  }","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilder.java#L142-L178","documentation":"Thrown by CreateTableBuilder.appendDataType when a column is marked auto-increment but its type is not BigInteger, Integer, or SmallInt. Only those numeric types map to AUTO_INCREMENT/BIGSERIAL/SERIAL/SMALLSERIAL dialect SQL.","triggerScenarios":"Building a CREATE TABLE where a column def was created with setIsNullable(false) plus auto-increment on a Varchar/Decimal/Text column.","commonSituations":"Custom migration accidentally enabling auto-increment on a non-integer key column; copy-pasted column builder with wrong type; generated migration code with mismatched column type.","solutions":["Change the column type to BigIntegerColumnDef, IntegerColumnDef, or SmallIntColumnDef.","Remove the auto-increment flag if the column should not be a generated key.","Verify columnDef type matches the intended primary-key semantics."],"exampleFix":"// before\nnewVarcharColumnDefBuilder().setColumnName(\"id\").setIsNullable(false).setLimit(40).build() // with autoincrement\n// after\nnewBigIntegerColumnDefBuilder().setColumnName(\"id\").setIsNullable(false).setAutoIncrement(true).build()","handlingStrategy":"validation","validationCode":"if (columnDef.isAutoIncrement() && !(columnDef instanceof BigIntegerColumnDef || columnDef instanceof IntegerColumnDef || columnDef instanceof SmallIntColumnDef)) { throw new IllegalArgumentException(\"autoincrement requires integer type\"); }","typeGuard":"boolean isAutoIncrementCapable(ColumnDef c) { return c instanceof BigIntegerColumnDef || c instanceof IntegerColumnDef || c instanceof SmallIntColumnDef; }","tryCatchPattern":null,"preventionTips":["Only set auto-increment on integer-family columns","Keep PK column type and auto-increment flags consistent","Review generated/copy-pasted column builders for type/flag mismatches"],"tags":["database","migration","autoincrement","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}