# How to implement non integer default auto fields

**URL:** <https://forum.djangoproject.com/t/how-to-implement-non-integer-default-auto-fields/43780>\
**Category:** ORM\
**Created:** [December 22, 2025, 12:13pm UTC](https://forum.djangoproject.com/t/how-to-implement-non-integer-default-auto-fields/43780 "2025-12-22T12:13:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![surister](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/surister/32/25012_2.png) [@surister](https://forum.djangoproject.com/u/surister)\
**Post date:** [December 22, 2025, 12:13pm UTC](https://forum.djangoproject.com/t/how-to-implement-non-integer-default-auto-fields/43780/1 "2025-12-22T12:13:21Z")

</div>

Hi, I’m developing the [django backend](https://github.com/crate/cratedb-django) for CrateDB, as we are a distributed database we do not support auto sequential integer generation, hence some form of random generation is need for unique PKs, we use elasticflakes (somewhate similar to uuid4).

I’d like my users to be able to do something like:  
`DEFAULT_AUTO_FIELD = "cratedb_django.fields.UUIDField"` but non integer auto field are not supported, as seen in [#32577 (Add support for `UUIDAutoField` `DEFAULT_AUTO_FIELD`) – Django](https://code.djangoproject.com/ticket/32577)

I’ve read [https://github.com/django/django/pull/18365](https://github.com/django/django/pull/18365) and [Db default UUID pk by nessita · Pull Request #24 · nessita/django · GitHub](https://github.com/nessita/django/pull/24) but it looks to me that there is still no way of me implementing this, currently I’m doing something like:

```python
    CRATE_SQL_AUTO_BIGINT = "bigint default (random() * 2^63-1)::bigint"
    CRATE_SQL_AUTO_INTEGER = "integer default (random() * 2^31-1)::integer"
    CRATE_SQL_AUTO_SMALLINTEGER = "smallint default (random() * 32767)::smallint"
    data_types = {
        # todo pgdiff - doc
        "AutoField": CRATE_SQL_AUTO_INTEGER,
        "BigAutoField": CRATE_SQL_AUTO_BIGINT,
        "SmallAutoField": CRATE_SQL_AUTO_SMALLINTEGER,
         ...

```

To have ‘randomness’ and integers for the PK, but this is not as robust as I’d like.

Am I missing anything or is it true that non-integer default auto ids are still not a thing, unfortunately?

---

<div class="post-metadata">

**Author:** ![charettes](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/charettes/32/27_2.png) [@charettes](https://forum.djangoproject.com/u/charettes)\
**Post date:** [December 22, 2025, 2:05pm UTC](https://forum.djangoproject.com/t/how-to-implement-non-integer-default-auto-fields/43780/2 "2025-12-22T14:05:22Z")

</div>

Hello @surister,

> Am I missing anything or is it true that non-integer default auto ids are still not a thing, unfortunately?

They are still not a thing.

Until we deprecate `DEFAULT_AUTO_FIELD` in favor of a more lax `DEFAULT_PK_FIELD` that allows any type of field that either have a `default` or `db_default` option set (and thus is `db_returning = True`) your best option is to define a field class inherits from `UUIDField` and `AutoField` and override all the methods that are problemtatic.

This is necessary to bypass a hardcoded check that `DEFAULT_AUTO_FIELD` references subclass `AutoField`

---

<div class="post-metadata">

**Author:** ![surister](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/surister/32/25012_2.png) [@surister](https://forum.djangoproject.com/u/surister)\
**Post date:** [December 22, 2025, 3:10pm UTC](https://forum.djangoproject.com/t/how-to-implement-non-integer-default-auto-fields/43780/3 "2025-12-22T15:10:50Z")

</div>

That’s what I feared, I didn’t like the random number generation thingy and was trying to avoid patching an inheritor class. But seems I don’t have an alternative, thanks!

If you guys need any feedback/help from a database implementor that is not the typical SQL model (as postgres/mysql) while improving this situation let me know, I’m always happy to help/contribute.

Cheers.
