Spend more time building what matters with our latest release. Learn More →

×

Announcing CockroachDB Support for Django ORM

Announcing CockroachDB Support for Django ORM
```

Django includes a full-featured ORM that simplifies interactions with a database--it’s one of the reasons it’s become one of the most popular web frameworks. Even so, you’re still left to manage scale yourself, and ensure the database is resilient and always on. That can be really hard to do with common Django databases like Postgres, SQLite, and MySQL. And that’s why today, we’re excited to announce a new CockroachDB backend for the Django ORM.

```

Using CockroachDB and Django gives you the ease of writing in Python while getting all the benefits of an open source, distributed SQL database. CockroachDB shards automatically, is naturally resilient, and is highly available. Here’s how to get started:

Installing django-cockroachdb

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

 pip install django-cockroachdb==3.0.* 

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

2. Configure the Django DATABASES setting similar to this:

 DATABASES = {
    'default': {
        'ENGINE': 'django_cockroachdb',
        'NAME': 'django',
        'USER': 'root',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '26257',
        # If connecting with SSL, remove the PASSWORD entry above and include
        # the section below, replacing the file paths as appropriate.
        'OPTIONS': {
            'sslmode': 'require',
            'sslrootcert': '/certs/ca.crt',
            'sslcert': '/certs/client.myprojectuser.crt',
            'sslkey': '/certs/client.myprojectuser.key',
        },
    },
} 

Helpful links:

Keep Reading

Peewee ORM + CockroachDB

This article was originally posted on the personal blog of the Peewee ORM founder, Charles Leifer. Peewee is a …

Read More
Building an Application With CockroachDB and SQLAlchemy

CockroachDB’s support for SQLAlchemy is currently in beta, but we’re actively developing new …

Read More
Database Scaling Strategies: A Practical Approach

In tech, we hear the importance of “scale” all the time. People plan for it, try to work around …

Read More
x
Developer Resources