Django backend for CockroachDB
Project description
CockroachDB backend for Django
Prerequisites
You must install 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 4.1.x:
pip install django-cockroachdb==4.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 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 asBigIntegerField
soIntegerField
is introspected byinspectdb
asBigIntegerField
. -
AutoField
andBigAutoField
are both stored as integer (64-bit) withDEFAULT unique_rowid()
.
Notes on Django QuerySets
-
QuerySet.explain()
acceptsverbose
,types
,opt
,vec
, anddistsql
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 22.1.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
- 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 likeunimplemented: table <...> is currently undergoing a schema change
if a later operation tries to modify the table before the asynchronous query finishes. A future version of CockroachDB may fix this.
-
Unsupported queries:
- Mixed type addition in SELECT:
unsupported binary operator: <int> + <float>
- Division that yields a different type:
unsupported binary operator: <int> / <int> (desired <int>)
- 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>
SmallAutoField
generates 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_3DPerimeter
,ST_3DExtent
,ST_Scale
, andST_LengthSpheroid
. - The
Length
database function isn't supported on geodetic fields: st_lengthspheroid(): unimplemented. Union
may crash with unknown signature: st_union(geometry, geometry).- The spheroid argument of ST_DistanceSpheroid
isn't supported:
unknown signature: st_distancespheroid(geometry, geometry, string)
. - These lookups aren't supported:
- Some database functions aren't supported:
Known issues and limitations in CockroachDB 21.2.x and earlier
- Unsupported query: UPDATE float column with integer column:
value type int doesn't match type FLOAT8 of column <name>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-cockroachdb-4.1.tar.gz
.
File metadata
- Download URL: django-cockroachdb-4.1.tar.gz
- Upload date:
- Size: 22.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f3a33828455b3759a4bd2852714266a4985de239ce558a233c8bf41414148bb |
|
MD5 | 6dedf132c5cea7a8fed613e9ffe794eb |
|
BLAKE2b-256 | ba051f9e4fe56b41a0320a651bbfea9ba0a11c780b99380e44d0e6fbdad8bc78 |
File details
Details for the file django_cockroachdb-4.1-py3-none-any.whl
.
File metadata
- Download URL: django_cockroachdb-4.1-py3-none-any.whl
- Upload date:
- Size: 25.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4497a5cb16de355ef05163ff4c49daa1c09a1400e3cc61b9a27fb81aea051234 |
|
MD5 | 0ef6239b381563e59e559e65fffc9acb |
|
BLAKE2b-256 | 90195fa2b98e24dc1dbff4b8f35f4f86571f9c6809422379987c8101f0c2f293 |