■VSCodeのターミナルをAnaconda Promptにする
settings.json
"terminal.integrated.shell.windows": "{Windowsディレクトリ}\\System32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/K",
"{Anacondaのインストールディレクトリ}\\Scripts\\activate.bat",
"{Anacondaのインストールディレクトリ}"
]
■仮想環境作成
conda create -n django python=3.7
■仮想環境に切り替える
activate django
■Djangoのインストール
pip install django
■Djangoのバージョン確認
python -m django --version
■djangoのプロジェクトを作成する
※VisualStudioでいうところのソリューションに相当するもの
django-admin startproject {プロジェクト名}
■djangoのアプリケーションを作成する
※VisualStudioでいうところのプロジェクトに相当するもの(1つのプロジェクトに対して複数のアプリを作成可能)
# 1.プロジェクト作成の際に作成される「manage.py」があるディレクトリに移動する
# 2.アプリケーションの作成
py manage.py startapp {アプリケーション名}
■テストサーバの実行
python manage.py runserver
■マイグレーションファイルの作成
python manage.py makemigrations {アプリケーション名}
■マイグレーションが自動生成するSQL(Create Table等)を確認する
python manage.py sqlmigrate {アプリケーション名} 0001
■マイグレーションファイルをDBに適用
python manage.py migrate
■プロジェクトに問題がないかチェックする
python manage.py check
■スーパーユーザの作成
python manage.py createsuperuser