Skip to main content

CockroachDB backend for Django

Prerequisites

You must install:

You can also use either:

The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources.

Install and usage

Use the version of django-cockroachdb that corresponds to your version of Django. For example, to get the latest compatible release for Django 5.2.x:

pip install django-cockroachdb==5.2.*

The minor release number of Django doesn't correspond to the minor release number of django-cockroachdb. Use the latest minor release of each.

Configure the Django DATABASES setting similar to this:

DATABASES = {
    'default': {
        'ENGINE': 'django_cockroachdb',
        'NAME': 'django',
        'USER': 'myprojectuser',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '26257',
        # If connecting with SSL, include the section below, replacing the
        # file paths as appropriate.
        'OPTIONS': {
            'sslmode': 'verify-full',
            'sslrootcert': '/certs/ca.crt',
            # Either sslcert and sslkey (below) or PASSWORD (above) is
            # required.
            'sslcert': '/certs/client.myprojectuser.crt',
            'sslkey': '/certs/client.myprojectuser.key',
            # If applicable
            'options': '--cluster={routing-id}',
        },
    },
}

If using Kerberos authentication, you can specify a custom service name in 'OPTIONS' using the key 'krbsrvname'.

Notes on Django fields

  • IntegerField uses the same storage as BigIntegerField so IntegerField is introspected by inspectdb as BigIntegerField.

  • AutoField and BigAutoField are both stored as integer (64-bit) with DEFAULT unique_rowid().

Notes on Django QuerySets

  • QuerySet.explain() accepts verbose, types, opt, vec, and distsql options which correspond to CockroachDB's parameters. For example:

    >>> Choice.objects.explain(opt=True, verbose=True)
    'scan polls_choice\n ├── columns: id:1 question_id:4 choice_text:2 votes:3\n ├── stats: [rows=1]\n ├── cost: 1.1\n ├── key: (1)\n ├── fd: (1)-->(2-4)\n └── prune: (1-4)'
    

FAQ

GIS support

To use django.contrib.gis with CockroachDB, use 'ENGINE': 'django_cockroachdb_gis' in Django's DATABASES setting.

Disabling CockroachDB telemetry

By default, CockroachDB sends the version of django-cockroachdb that you're using back to Cockroach Labs. To disable this, set DISABLE_COCKROACHDB_TELEMETRY = True in your Django settings.

Known issues and limitations in CockroachDB 26.3.x and earlier

Known issues and limitations in CockroachDB 26.2.x and earlier

Known issues and limitations in CockroachDB 24.3.x and earlier

  • CockroachDB executes ALTER COLUMN queries asynchronously which is at odds with Django's assumption that the database is altered before the next migration operation begins. CockroachDB will give an error like unimplemented: table <...> is currently undergoing a schema change if a later operation tries to modify the table before the asynchronous query finishes.

Metadata

Release files for django-cockroachdb 5.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-cockroachdb 5.2.2
File Size Uploaded
django_cockroachdb-5.2.2.tar.gz 25.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-cockroachdb 5.2.2
File Interpreter ABI Platform
django_cockroachdb-5.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 53.6 kB

Release files / django_cockroachdb-5.2.2.tar.gz

Download URL django_cockroachdb-5.2.2.tar.gz
Size 25.8 kB
Tags Source
SHA-256 checksum
How to use checksums
be9ad8fc3e6f68c39fd4e3f473bdf7329b988546dcbcd242b3592f9e76db322c
BLAKE2b-256 checksum
How to use checksums
53979f59e9802d6bf549e453ba10b0707891d62fac75259494727b6ddce538ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / django_cockroachdb-5.2.2-py3-none-any.whl

Download URL django_cockroachdb-5.2.2-py3-none-any.whl
Size 27.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
516b8d068a1a8f1268ac7ec7300564a33a3b0d5b0265579c3ed480b2e5a68472
BLAKE2b-256 checksum
How to use checksums
b4247c0c675ea1f2f0b55bb53ab00acf2d05c9b054cae6a2d78479a38a316a3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page