概要
runserverしようとしたところ、
RuntimeError: Model class pairnite.users.models.User doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
というエラーが出てしまい、色々調べて試してみてを繰り返したのですが、どうにも解決できず、この場で質問させていただきます。
不明な点や足りない部分があれば、お気軽にご質問ください。
環境
Python3.7.3
Django3.0.6
わかる範囲での原因の予想
リアルタイムチャット昨日のため、websocketのchannelsの導入によるエラー
ディレクトリ構造
一番下に記載
コード(足りない部分あれば教えてください)
settings.py
1""" 2Django settings for config project. 3 4Generated by 'django-admin startproject' using Django 3.0.6. 5 6For more information on this file, see 7https://docs.djangoproject.com/en/3.0/topics/settings/ 8 9For the full list of settings and their values, see 10https://docs.djangoproject.com/en/3.0/ref/settings/ 11""" 12 13import os 14 15# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 18 19# Quick-start development settings - unsuitable for production 20# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ 21 22# SECURITY WARNING: keep the secret key used in production secret! 23SECRET_KEY = '&q9t+ez0k4r_ow$vm!y=mlgxtl4qk12ph58jyvgj+tshe1' 24 25# SECURITY WARNING: don't run with debug turned on in production! 26DEBUG = True 27 28ALLOWED_HOSTS = [] 29 30AUTH_USER_MODEL = 'users.User' 31 32 33# Application definition 34INSTALLED_APPS = [ 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 'users.apps.UsersConfig', 42 'relations.apps.RelationsConfig', 43 # フォーム処理用 44 "widget_tweaks", 45 'chat.apps.ChatConfig', 46 # # リアルタイムチャット実現用 47 'channels', 48] 49 50 51MIDDLEWARE = [ 52 'django.middleware.security.SecurityMiddleware', 53 'django.contrib.sessions.middleware.SessionMiddleware', 54 'django.middleware.common.CommonMiddleware', 55 'django.middleware.csrf.CsrfViewMiddleware', 56 'django.contrib.auth.middleware.AuthenticationMiddleware', 57 'django.contrib.messages.middleware.MessageMiddleware', 58 'django.middleware.clickjacking.XFrameOptionsMiddleware', 59] 60 61ROOT_URLCONF = 'config.urls' 62 63TEMPLATES = [ 64 { 65 'BACKEND': 'django.template.backends.django.DjangoTemplates', 66 'DIRS': [os.path.join(BASE_DIR, 'templates')], 67 'APP_DIRS': True, 68 'OPTIONS': { 69 'context_processors': [ 70 'django.template.context_processors.debug', 71 'django.template.context_processors.request', 72 'django.contrib.auth.context_processors.auth', 73 'django.contrib.messages.context_processors.messages', 74 ], 75 }, 76 }, 77] 78 79WSGI_APPLICATION = 'config.wsgi.application' 80 81 82# Database 83# https://docs.djangoproject.com/en/3.0/ref/settings/#databases 84 85DATABASES = { 86 'default': { 87 'ENGINE': 'django.db.backends.sqlite3', 88 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 89 } 90} 91 92 93# Password validation 94# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators 95 96AUTH_PASSWORD_VALIDATORS = [ 97 { 98 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 99 }, 100 { 101 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 102 }, 103 { 104 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 105 }, 106 { 107 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 108 }, 109] 110 111 112# Internationalization 113# https://docs.djangoproject.com/en/3.0/topics/i18n/ 114 115LANGUAGE_CODE = 'ja' 116 117TIME_ZONE = 'Asia/Tokyo' 118 119USE_I18N = True 120 121USE_L10N = True 122 123USE_TZ = True 124 125 126# Static files (CSS, JavaScript, Images) 127# https://docs.djangoproject.com/en/3.0/howto/static-files/ 128 129STATIC_URL = '/static/' 130 131# アイコン画像の保存先設定 132MEDIA_ROOT = os.path.join(BASE_DIR, 'media') 133MEDIA_URL = '/media/' 134 135# ログイン後のリダイレクト先 136LOGIN_REDIRECT_URL = "users:home" 137# ログアウト後のリダイレクト先 138LOGOUT_REDIRECT_URL = "users:index" 139# Channelsを有効化。channelsは非同期処理をサポートする。 140# https://qiita.com/massa142/items/cbd508efe0c45b618b34#:~:text=Django%20Channels%E3%81%A8%E3%81%AF&text=Channels%E3%81%AF%E3%80%81Django%E3%81%8CWebSocket,%E3%81%AB%E3%81%99%E3%82%8B%E3%83%97%E3%83%AD%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%81%A7%E3%81%82%E3%82%8B%E3%80%82 141ASGI_APPLICATION = 'config.routing.application' 142# channel layerの有効化。channel layerは複数ユーザーの間でメッセージを共有できる仕組み。docker環境に写したとき、hostsの第一引数をredisに変えた方がいいかも。 143# http://www.denzow.me/entry/2018/04/03/002351 144CHANNEL_LAYERS = { 145 'default': { 146 'BACKEND': 'channels_redis.core.RedisChannelLayer', 147 'CONFIG': { 148 "hosts": [("127.0.0.1", 6379)], 149 }, 150 }, 151} 152
chat/routings.py
1from django.urls import path 2 3from . import consumers 4 5websocket_urlpatterns = [ 6 path('ws/chat/<str:room_name>/', consumers.WSBackend), 7]
chat/urls.py
1from django.urls import path 2# from .views import index, user, reaction, chat 3from django.conf import settings 4from django.conf.urls.static import static 5# from .controller import chat_controller 6from . import views 7 8app_name = 'chat' 9 10urlpatterns = [ 11 path('create/<int:user_id>', views.create, name='chat_create'), 12 path('show/<int:room_id>', views.show, name='chat_show'), 13 path('create/<int:room_id>/messages/', views.messages, name='chat_messages'), 14]
config/urls.py
1from django.contrib import admin 2from django.urls import include, path 3from django.conf import settings 4from django.conf.urls.static import static 5 6urlpatterns = [ 7 path('admin/', admin.site.urls), 8 path('users/', include('users.urls')), 9 10 # ログイン用 11 path('users/', include('django.contrib.auth.urls')), 12 # チャット用 13 path('chat/', include('chat.urls')), 14 # リレーション用 15 path('relations/', include('relations.urls')), 16] 17 18# 画像をアドミン以外の人でも見れるようにする 19urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 20
ディレクトリ構造
量が多いです。
chatディレクトリとconfigディレクトリ以外見る必要ないと思います。
. ├── Pipfile ├── Pipfile.lock ├── chat │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-37.pyc │ │ ├── admin.cpython-37.pyc │ │ ├── apps.cpython-37.pyc │ │ ├── chat_controller.cpython-37.pyc │ │ ├── models.cpython-37.pyc │ │ ├── urls.cpython-37.pyc │ │ └── views.cpython-37.pyc │ ├── admin.py │ ├── apps.py │ ├── chat_controller.py │ ├── consumers.py │ ├── forms.py │ ├── migrations │ │ ├── __init__.py │ │ └── __pycache__ │ │ └── __init__.cpython-37.pyc │ ├── models.py │ ├── routing.py │ ├── tests.py │ ├── urls.py │ └── views.py ├── config │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-37.pyc │ │ ├── routing.cpython-37.pyc │ │ ├── settings.cpython-37.pyc │ │ ├── urls.cpython-37.pyc │ │ └── wsgi.cpython-37.pyc │ ├── routing.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── db.sqlite3 ├── manage.py ├── media │ └── icon │ ├── 1487784.jpg │ ├── Hi_�\202��\203��\203\210�\203\233�\203��\203\210_1.png │ ├── default.jpg │ ├── �\202��\202��\203��\203��\203��\202��\203��\203\203�\203\210_2020-06-06_13.34.42.png │ ├── �\203��\202��\226\207�\227ZZOO_w.jpg │ └── �\214�\221�\226��\202��\202場�\217模.jpg ├── relations │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-37.pyc │ │ ├── admin.cpython-37.pyc │ │ ├── apps.cpython-37.pyc │ │ ├── forms.cpython-37.pyc │ │ ├── models.cpython-37.pyc │ │ ├── urls.cpython-37.pyc │ │ └── views.cpython-37.pyc │ ├── admin.py │ ├── apps.py │ ├── forms.py │ ├── migrations │ │ ├── 0001_initial.py │ │ ├── __init__.py │ │ └── __pycache__ │ │ ├── 0001_initial.cpython-37.pyc │ │ └── __init__.cpython-37.pyc │ ├── models.py │ ├── tests.py │ ├── urls.py │ └── views.py ├── templates │ ├── base.html │ ├── chat │ │ └── chat.html │ ├── home.html │ ├── index.html │ ├── registration │ │ └── login.html │ ├── relations │ │ ├── dislike.html │ │ └── like.html │ └── users │ ├── delete.html │ ├── detail.html │ ├── mail_change.html │ ├── password_change.html │ ├── password_change_done.html │ ├── signup.html │ └── update.html └── users ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-37.pyc │ ├── admin.cpython-37.pyc │ ├── apps.cpython-37.pyc │ ├── forms.cpython-37.pyc │ ├── mixins.cpython-37.pyc │ ├── models.cpython-37.pyc │ ├── urls.cpython-37.pyc │ └── views.cpython-37.pyc ├── admin.py ├── apps.py ├── forms.py ├── migrations │ ├── 0001_initial.py │ ├── __init__.py │ └── __pycache__ │ ├── 0001_initial.cpython-37.pyc │ ├── 0002_auto_20200606_1415.cpython-37.pyc │ ├── 0003_auto_20200607_1537.cpython-37.pyc │ ├── 0004_auto_20200608_0835.cpython-37.pyc │ └── __init__.cpython-37.pyc ├── mixins.py ├── models.py ├── tests.py ├── urls.py └── views.py
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/06/16 21:52
2020/06/17 01:56
2020/06/17 10:36
2020/06/17 10:41
2020/06/17 21:48
2020/06/18 01:54