greenrobot/greenDAO · error · RuntimeException

AUTOINCREMENT is only available to primary key properties…

Error message

AUTOINCREMENT is only available to primary key properties of type long/Long

What it means

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.

Solutions

  1. Ensure the property is created with addLongProperty(...) and call .primarykey() before .autoincrement().
  2. Remove autoincrement() if the column needn't auto-increment; greenDAO ids are often fine without it.
  3. For non-Long primary keys, drop AUTOINCREMENT — SQLite only supports it for INTEGER PRIMARY KEY.
  4. Use entity.addIdProperty() which sets up a proper Long primary key.

Example fix

// before
entity.addIntProperty("id").primaryKey().autoincrement(); // wrong type
// after
entity.addLongProperty("id").primaryKey().autoincrement();
Defensive patterns

Strategy: validation

Validate before calling

// AUTOINCREMENT requires Long primary key
if (!isLongPk(property)) {
    throw new IllegalArgumentException("autoincrement() requires addLongProperty(...).primaryKey()");
}

Try / catch

try {
    builder.autoincrement();
} catch (RuntimeException e) {
    if (e.getMessage().startsWith("AUTOINCREMENT is only available")) {
        throw new IllegalStateException("Use addLongProperty(...).primaryKey().autoincrement()", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of greenrobot/greenDAO@0bbb338e17 (2026-09-08). Data as JSON: /api/errors/ded7f6d87b845173. Report an issue: GitHub.

Appendix: source

Thrown at DaoGenerator/src/org/greenrobot/greendao/generator/Property.java:78

            property.primaryKey = true;
            return this;
        }

        public PropertyBuilder primaryKeyAsc() {
            property.primaryKey = true;
            property.pkAsc = true;
            return this;
        }

        public PropertyBuilder primaryKeyDesc() {
            property.primaryKey = true;
            property.pkDesc = true;
            return this;
        }

        public PropertyBuilder autoincrement() {
            if (!property.primaryKey || property.propertyType != PropertyType.Long) {
                throw new RuntimeException(
                        "AUTOINCREMENT is only available to primary key properties of type long/Long");
            }
            property.pkAutoincrement = true;
            return this;
        }

        public PropertyBuilder unique() {
            property.unique = true;
            return this;
        }

        public PropertyBuilder notNull() {
            property.notNull = true;
            return this;
        }

        public PropertyBuilder nonPrimitiveType() {
            if (!property.propertyType.isScalar()) {

View on GitHub (pinned to 0bbb338e17)