前提
Djangoの公式チュートリアルをやっているのですが、チュートリアルその2(https://docs.djangoproject.com/ja/4.0/intro/tutorial02/#writing-your-first-django-app-part-2)
の下記コマンドを実行したところ、期待した動作ではなくエラーとなってしまいました。
「これで Django は、 polls アプリケーションが含まれていることを認識できます。もうひとつコマンドを実行しましょう:」
$ python manage.py makemigrations polls
チュートリアルを見直したりエラーメッセージで検索してみたりしましたが、わかりませんでした。どこを修正すればよいでしょうか?
実現したいこと
makemigrationのコマンドを通したい
発生している問題・エラーメッセージ
Traceback (most recent call last): File "C:\Users\hitom\myhome\hobby\djangoStudy\mysite\manage.py", line 22, in <module> main() File "C:\Users\hitom\myhome\hobby\djangoStudy\mysite\manage.py", line 18, in main execute_from_command_line(sys.argv) File "C:\Users\hitom\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line utility.execute() File "C:\Users\hitom\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\django\core\management\__init__.py", line 420, in execute django.setup() File "C:\Users\hitom\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\django\__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "C:\Users\hitom\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\django\apps\registry.py", line 91, in populate app_config = AppConfig.create(entry) File "C:\Users\hitom\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\django\apps\config.py", line 213, in create mod = import_module(mod_path) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked ModuleNotFoundError: No module named 'polls'
該当のソースコード
settings.py
Python
1""" 2Django settings for mysite project. 3 4Generated by 'django-admin startproject' using Django 4.0.6. 5 6For more information on this file, see 7https://docs.djangoproject.com/en/4.0/topics/settings/ 8 9For the full list of settings and their values, see 10https://docs.djangoproject.com/en/4.0/ref/settings/ 11""" 12 13from pathlib import Path 14 15# Build paths inside the project like this: BASE_DIR / 'subdir'. 16BASE_DIR = Path(__file__).resolve().parent.parent 17 18 19# Quick-start development settings - unsuitable for production 20# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ 21 22# SECURITY WARNING: keep the secret key used in production secret! 23SECRET_KEY = 'django-insecure-0jxxk*n30(x8_+6l$k)^fxd=8^#s&72k&4f3a7*6j7tx+8&njs' 24 25# SECURITY WARNING: don't run with debug turned on in production! 26DEBUG = True 27 28ALLOWED_HOSTS = [] 29 30 31# Application definition 32 33INSTALLED_APPS = [ 34 'polls.apps.PollsConfig', 35 'django.contrib.admin', 36 'django.contrib.auth', 37 'django.contrib.contenttypes', 38 'django.contrib.sessions', 39 'django.contrib.messages', 40 'django.contrib.staticfiles', 41] 42 43MIDDLEWARE = [ 44 'django.middleware.security.SecurityMiddleware', 45 'django.contrib.sessions.middleware.SessionMiddleware', 46 'django.middleware.common.CommonMiddleware', 47 'django.middleware.csrf.CsrfViewMiddleware', 48 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 'django.contrib.messages.middleware.MessageMiddleware', 50 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51] 52 53ROOT_URLCONF = 'mysite.urls' 54 55TEMPLATES = [ 56 { 57 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 'DIRS': [], 59 'APP_DIRS': True, 60 'OPTIONS': { 61 'context_processors': [ 62 'django.template.context_processors.debug', 63 'django.template.context_processors.request', 64 'django.contrib.auth.context_processors.auth', 65 'django.contrib.messages.context_processors.messages', 66 ], 67 }, 68 }, 69] 70 71WSGI_APPLICATION = 'mysite.wsgi.application' 72 73 74# Database 75# https://docs.djangoproject.com/en/4.0/ref/settings/#databases 76 77DATABASES = { 78 'default': { 79 'ENGINE': 'django.db.backends.mysql', 80 'NAME': 'test1', 81 'USER':'root', 82 'PASSWORD':'MySQL0014', 83 } 84} 85 86 87# Password validation 88# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators 89 90AUTH_PASSWORD_VALIDATORS = [ 91 { 92 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 93 }, 94 { 95 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 96 }, 97 { 98 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 99 }, 100 { 101 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 102 }, 103] 104 105 106# Internationalization 107# https://docs.djangoproject.com/en/4.0/topics/i18n/ 108 109LANGUAGE_CODE = 'en-us' 110 111TIME_ZONE = 'JST' 112 113USE_I18N = True 114 115USE_TZ = True 116 117 118# Static files (CSS, JavaScript, Images) 119# https://docs.djangoproject.com/en/4.0/howto/static-files/ 120 121STATIC_URL = 'static/' 122 123# Default primary key field type 124# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field 125 126DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 127
models.py
Python
1from django.db import models 2 3# Create your models here. 4class Question(models.Model): 5 question_text=models.CharField(max_length=200) 6 pub_date =models.DateTileField('date piblished') 7 8 class Choice(models.Model): 9 question = models.ForeignKey(Question,on_delete=models.CASCADE) 10 choice_text = models.CharField(max_length=200) 11 votes=models.IntegerField(default=0)
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ディレクトリ構成はこちらです
回答2件
あなたの回答
tips
プレビュー