Skip to main content

Django backend for CockroachDB

Project description

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 25.4.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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_cockroachdb-5.2.1.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_cockroachdb-5.2.1-py3-none-any.whl (27.3 kB view details)

Uploaded Python 3

File details

Details for the file django_cockroachdb-5.2.1.tar.gz.

File metadata

  • Download URL: django_cockroachdb-5.2.1.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for django_cockroachdb-5.2.1.tar.gz
Algorithm Hash digest
SHA256 ce2d872896d7bc241a126db741345bb730d63c7197804759f3c5da772eb4c196
MD5 7b73c5d76c056da8390d688dff53ce6f
BLAKE2b-256 49442f0f9aff1cd4512167824cf293581a0d25f6adca81901bc8b3c97f3c400c

See more details on using hashes here.

File details

Details for the file django_cockroachdb-5.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_cockroachdb-5.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6b71962e55c3d42b6fbe3e0462c78a3cffdbd1bc0cd2b7cb288852c8667f06a7
MD5 ad5732ce1626e7996337a6c04682a56d
BLAKE2b-256 5cf3fcbfbf7c2dee4facba382dd40703eca0cd6fa01ad08a95039873498087c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page