Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.