Skip to content

Instantly share code, notes, and snippets.

@nakagami
Last active April 7, 2019 13:54
Show Gist options
  • Save nakagami/2c261b306a50e9ecd84734c0e74e2011 to your computer and use it in GitHub Desktop.
Save nakagami/2c261b306a50e9ecd84734c0e74e2011 to your computer and use it in GitHub Desktop.
Quickstart with Django and pure python database drivers (2019-04-06)

Pure python なデーターベースドライバーを Django 2.2 LTS で使う

(参考)データーベースバックエンドを読む、そして書く https://gist.github.com/nakagami/098db7387d78ab9c6aa85d77a0eeecf5

PostgreSQL

psql -U postgres
create database pg_sample;
python3 -m venv pgvenv
. pgvenv/bin/activate
pip install -U pip
pip install django==2.2 django-minipg==0.3.5 minipg
django-admin startproject pgsite
cd pgsite
vi pgsite/settings.py
DATABASES = {
    'default': {
        'ENGINE': 'postgresql_minipg',
        'NAME': 'pg_sample',
        'HOST': 'localhost',
        'USER': 'postgres',
        'PASSWORD': 'xxxxxx',
    }
}
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver

MySQL

mysql -uroot -p
create database my_sample;
python3 -m venv myvenv
. myvenv/bin/activate
pip install -U pip
pip install django==2.2 "django-cymysql>=2.2,<2.3" cymysql
django-admin startproject mysite
cd mysite
vi mysite/settings.py
DATABASES = {
    'default': {
        'ENGINE': 'mysql_cymysql',
        'NAME': 'my_sample',
        'HOST': 'localhost',
        'USER': 'root',
        'PASSWORD': 'xxxxxx',
    }
}
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment