前提・実現したいこと
動かして学ぶ!pythonDjango開発入門という本で学習中です。
Djangoを使いwebアプリケーションを作ろうとしているのですがrunserverでエラーが出たの解決策を教えて頂きたいです。
右も左もわからず回答していただくには質問内容が乏しいかと思いますがよろしくお願いします、、、
環境
Mac M1 version 11.3
python 3.9.2
Django 3.2
上記の本ではvenvを使っていましたが、condaを使っています。
発生している問題・エラーメッセージ
/usr/local/Caskroom/miniforge/base/envs/webapp_env/bin/python /Users/haru/private_diary/manage.py runserver 2021-05-05 09:16:51,562 [INFO] /usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/utils/autoreload.py(Line:636) Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). Exception in thread django-main-thread: Traceback (most recent call last): File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection self.connect() File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/db/backends/base/base.py", line 200, in connect self.connection = self.get_new_connection(conn_params) File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection connection = Database.connect(**conn_params) File "/Users/haru/.local/lib/python3.9/site-packages/psycopg2/__init__.py", line 127, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) psycopg2.OperationalError: FATAL: database "private_diary" does not exist The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/threading.py", line 954, in _bootstrap_inner self.run() File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/threading.py", line 892, in run self._target(*self._args, **self._kwargs) File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/utils/autoreload.py", line 64, in wrapper fn(*args, **kwargs) File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run self.check_migrations() File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/core/management/base.py", line 486, in check_migrations executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS]) File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/db/migrations/executor.py", line 18, in __init__ self.loader = MigrationLoader(self.connection) File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/db/migrations/loader.py", line 53, in __init__ self.build_graph() File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/db/migrations/loader.py", line 220, in build_graph self.applied_migrations = recorder.applied_migrations() File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations if self.has_table(): File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/db/migrations/recorder.py", line 55, in has_table with self.connection.cursor() as cursor: File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/db/backends/base/base.py", line 259, in cursor return self._cursor() File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/db/backends/base/base.py", line 235, in _cursor self.ensure_connection() File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection self.connect() File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection self.connect() File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/db/backends/base/base.py", line 200, in connect self.connection = self.get_new_connection(conn_params) File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) File "/usr/local/Caskroom/miniforge/base/envs/webapp_env/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection connection = Database.connect(**conn_params) File "/Users/haru/.local/lib/python3.9/site-packages/psycopg2/__init__.py", line 127, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) django.db.utils.OperationalError: FATAL: database "private_diary" does not exist
試したこと
python
1django.db.utils.OperationalError: FATAL: database "private_diary" does not exist
ここからprivate_diaryというデータベースを作れていないのか思いターミナルに「psql -l]と打ちこむとprivate_diaryは作れていました。
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
----------------+-------+----------+---------+-------+-------------------
postgres | haru | UTF8 | C | C |
privatet_diary | haru | UTF8 | C | C |
以下略
python
1DATABASES = { 2 'default': { 3 'ENGINE': 'django.db.backends.postgresql_psycopg2', 4 'NAME': "private_diary", 5 "USER": os.environ.get("DB_USER"), 6 "PASSWORD": os.environ.get("DB_PASSWORD"), 7 "HOST": '', 8 "PORT": '',
settinngs.pyの方は本の通りに記述しています。
他にも諸々試しましたが一日かけても解決せず、、回答していただく上で不明な点あれば補足しますのでよろしくお願いします。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/05/05 04:10
2021/05/05 04:47
2021/05/05 05:09
退会済みユーザー
2021/05/05 10:32
退会済みユーザー
2021/05/05 10:32