{"record":{"id":"ded7f6d87b845173","repo":"greenrobot/greenDAO","slug":"autoincrement-is-only-available-to-primary-key-pro","errorCode":null,"errorMessage":"AUTOINCREMENT is only available to primary key properties of type long/Long","messagePattern":"AUTOINCREMENT is only available to primary key properties of type long/Long","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"DaoGenerator/src/org/greenrobot/greendao/generator/Property.java","lineNumber":78,"sourceCode":"            property.primaryKey = true;\n            return this;\n        }\n\n        public PropertyBuilder primaryKeyAsc() {\n            property.primaryKey = true;\n            property.pkAsc = true;\n            return this;\n        }\n\n        public PropertyBuilder primaryKeyDesc() {\n            property.primaryKey = true;\n            property.pkDesc = true;\n            return this;\n        }\n\n        public PropertyBuilder autoincrement() {\n            if (!property.primaryKey || property.propertyType != PropertyType.Long) {\n                throw new RuntimeException(\n                        \"AUTOINCREMENT is only available to primary key properties of type long/Long\");\n            }\n            property.pkAutoincrement = true;\n            return this;\n        }\n\n        public PropertyBuilder unique() {\n            property.unique = true;\n            return this;\n        }\n\n        public PropertyBuilder notNull() {\n            property.notNull = true;\n            return this;\n        }\n\n        public PropertyBuilder nonPrimitiveType() {\n            if (!property.propertyType.isScalar()) {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/greenrobot/greenDAO/blob/0bbb338e17c4cf28aba5aae62d42f73f50186157/DaoGenerator/src/org/greenrobot/greendao/generator/Property.java#L60-L96","documentation":"PropertyBuilder.autoincrement() requires the property to be a primary key of type Long, mirroring SQLite's rule that AUTOINCREMENT is only valid on INTEGER PRIMARY KEY columns. Calling it on a non-primary-key or non-Long property throws a RuntimeException at schema definition time.","triggerScenarios":"Calling .autoincrement() on a builder from addIntProperty/addStringProperty/etc., or on a Long property without primarykey(), or using primaryKeyAsc().autoincrement() where the property type is not Long.","commonSituations":"Translating SQL DDL (with AUTOINCREMENT) directly to the DSL; applying autoincrement to a String or Integer key; forgetting to call primarykey() before autoincrement in the builder chain.","solutions":["Ensure the property is created with addLongProperty(...) and call .primarykey() before .autoincrement().","Remove autoincrement() if the column needn't auto-increment; greenDAO ids are often fine without it.","For non-Long primary keys, drop AUTOINCREMENT — SQLite only supports it for INTEGER PRIMARY KEY.","Use entity.addIdProperty() which sets up a proper Long primary key."],"exampleFix":"// before\nentity.addIntProperty(\"id\").primaryKey().autoincrement(); // wrong type\n// after\nentity.addLongProperty(\"id\").primaryKey().autoincrement();","handlingStrategy":"validation","validationCode":"// AUTOINCREMENT requires Long primary key\nif (!isLongPk(property)) {\n    throw new IllegalArgumentException(\"autoincrement() requires addLongProperty(...).primaryKey()\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    builder.autoincrement();\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"AUTOINCREMENT is only available\")) {\n        throw new IllegalStateException(\"Use addLongProperty(...).primaryKey().autoincrement()\", e);\n    }\n    throw e;\n}","preventionTips":["Only call autoincrement() on addLongProperty builders","Always chain .primaryKey() before .autoincrement()","Remember SQLite limits AUTOINCREMENT to INTEGER PRIMARY KEY","Prefer entity.addIdProperty() for standard Long PKs"],"tags":["greendao","code-generation","schema","sqlite"],"backgroundTag":"invalid-argument-value","analyzedSha":"0bbb338e17c4cf28aba5aae62d42f73f50186157","analyzedAt":"2026-09-08T03:22:36.050Z","contentChangedAt":"2026-09-08T03:22:36.050Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}