https://end0tknr.hateblo.jp/entry/20230305/1677958553
先程の上記entryでは、djangoのdefault dbであるsqliteを使用していましたが、 mysqlへの接続に変更します。
参考url
- https://www.tohoho-web.com/django/index.html
- https://docs.djangoproject.com/en/4.1/ref/settings/#databases
- https://qiita.com/kanazawa1226/items/e222604943c500801746
mysql接続ドライバのinstall
$ pip install mysqlclient
djangoの設定変更 - config/settings.py
DATABASES = { 'default': { 'ENGINE' : 'django.db.backends.mysql', 'NAME' : 'django', 'USER' : 'root', 'PASSWORD': '', 'HOST' : '127.0.0.1', 'PORT' : '3306', } } # DATABASES = { # 'default': { # 'ENGINE': 'django.db.backends.sqlite3', # 'NAME': BASE_DIR / 'db.sqlite3', # } # }
DBマイグレーション
$ rm -rf books/migrations/* $ python manage.py makemigrations books $ python manage.py migrate
管理ユーザの再作成
$ python3 manage.py createsuperuser