1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Djangoの各種データベース用の設定をまとめてみた(MySQL、PostgreSQL)

Last updated at Posted at 2020-05-14

Djangoで使用するデータベースをコロコロ変える羽目になったときにやりやすいようにまとめました
#SQLite3

settings.py
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

#MySQL

settings.py
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'DATABASE',  # Database名
        'USER': 'USER',  # ユーザID
        'PASSWORD': 'password',  # ユーザIDのパスワード
        'HOST': 'localhost',  # ホスト名
        'PORT': '3306',
    }
}

必要なライブラリ:mysqlclient
PyMySQLも使えますが推奨されているのはmysqlclientです。

#POSTGRESQL

settings.py
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'DATABASE',  # Database名
        'USER': 'USER',  # ユーザID
        'PASSWORD': 'password',  # ユーザIDのパスワード
        'HOST': 'localhost',  # ホスト名
        'PORT': '5432',
    }
}

必要なライブラリ:psycopg2

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?