Home United States USA — software How To Use CockroachDB With Your Django Application

How To Use CockroachDB With Your Django Application

134
0
SHARE

Looking for more information about how to use CockroachDB with Django? Check out this step-by-step tutorial to learn more.
This tutorial is intended to be a quick ramp-up on CockroachDB with Django. In case you’re searching for a proper Django tutorial, this is not it. At the time of writing, django-cockroachdb library is available in two versions, (2 and 3). This tutorial will cover version 3, and is inspired by the Digital Ocean tutorial using Django with PostgreSQL. I am going to highlight the steps where this tutorial differs from the original. For everything else, we will assume the tutorial is followed as is. I originally wrote this post two years ago and had since updated it as CockroachDB RBAC is no longer an enterprise-only feature so we can skip that step. I’m also including steps to launch a Docker instance to make this more portable and comprehensive. I am going to run a Docker container with Ubuntu and expose port 8080 for the DB Console, port 26257 for the SQL shell, and port 8000 for my Django application. I will install CockroachDB and run the Django app inside the container. In a terminal, execute the following command to launch this container: docker run -d -p 8080:8080 -p 26257:26257 -p 8000:8000 –name django -i -t ubuntu /bin/bash Then execute the following command to connect to the interactive shell inside this container: docker exec -it django bash The first thing we want to do is install some necessary dependencies.

Continue reading...