CockroachDB backend for Django
Prerequisites
You must install:
- psycopg, which may have some prerequisites depending on which version you use.
You can also use either:
-
psycopg2, which has some prerequisites of its own.
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 6.1.x:
pip install django-cockroachdb==6.1.*
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
-
IntegerFielduses the same storage asBigIntegerFieldsoIntegerFieldis introspected byinspectdbasBigIntegerField. -
AutoFieldandBigAutoFieldare both stored as integer (64-bit) withDEFAULT unique_rowid().
Notes on Django QuerySets
-
QuerySet.explain()acceptsverbose,types,opt,vec, anddistsqloptions 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
-
CockroachDB can't disable constraint checking, which means certain things in Django like forward references in fixtures aren't supported.
-
Migrations have some limitations. CockroachDB doesn't support:
- changing column type if it's part of an index
- dropping or changing a table's primary key
-
The
Field.db_commentandMeta.db_table_commentoptions aren't supported due to poor performance. -
Unsupported database functions:
-
UniqueConstraint.nulls_distinctisn't supported. -
Unsupported queries:
- Mixed type addition in SELECT:
unsupported binary operator: <int> + <float> - The power() database function doesn't accept negative exponents:
power(): integer out of range - sum() doesn't support arguments of different types:
sum(): unsupported binary operator: <float> + <int> - greatest() doesn't support arguments of different types:
greatest(): expected <arg> to be of type <type>, found type <other type> SmallAutoFieldgenerates values that are too large for any corresponding foreign keys.
- Mixed type addition in SELECT:
-
GIS:
- Some database functions aren't supported:
AsGML,AsKML,AsSVG, andGeometryDistance. - Some 3D functions or signatures aren't supported:
ST_3DExtent,ST_Scale, andST_LengthSpheroid. - The
Lengthdatabase function isn't supported on geodetic fields: st_lengthspheroid(): unimplemented. Unionmay crash with unknown signature: st_union(geometry, geometry).- These lookups aren't supported:
- Some database functions aren't supported:
Known issues and limitations in CockroachDB 26.2.x and earlier
-
GIS:
- The
ST_3DPerimeterfunction isn't supported. - The spheroid argument of
ST_DistanceSpheroidisn't supported.
- The
-
Queries which use division that yields a different type aren't supported:
unsupported binary operator: <int> / <int> (desired <int>) -
The
BitXoraggregate isn't supported.
Known issues and limitations in CockroachDB 24.3.x and earlier
- CockroachDB executes
ALTER COLUMNqueries 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 likeunimplemented: table <...> is currently undergoing a schema changeif a later operation tries to modify the table before the asynchronous query finishes.
Metadata
Release files for django-cockroachdb 6.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_cockroachdb-6.1.1.tar.gz | 27.8 kB | Without provenance | Details for django_cockroachdb-6.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_cockroachdb-6.1.1-py3-none-any.whl | Python 3 | none | any | Details for django_cockroachdb-6.1.1-py3-none-any.whl |
Total release size: 57.0 kB
Release files / django_cockroachdb-6.1.1.tar.gz
| Download URL | django_cockroachdb-6.1.1.tar.gz |
|---|---|
| Size | 27.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
78c396093b9b8868f9e7ac4b68a0f4e3489160d7c4ce80212295f0a49f71876a
|
|
BLAKE2b-256 checksum How to use checksums |
be79291b8e777896fed1ab5dcee0cb68b7f92c755a6f9b03e149c5e694cdb21f
|
| 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-6.1.1-py3-none-any.whl
| Download URL | django_cockroachdb-6.1.1-py3-none-any.whl |
|---|---|
| Size | 29.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
36d8d2e8d32968dbf17be5d9ea7c8cdc272f00b4ddeb63b89c575dc2ba1caf44
|
|
BLAKE2b-256 checksum How to use checksums |
d2fc75365902f9f5fdbccb857ac2220f6c5bcb04c1c1dd17f6f5932782935199
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Security for django-cockroachdb 6.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.