인프런 커뮤니티 질문&답변

Zmann님의 프로필 이미지
Zmann

작성한 질문수

실리콘밸리 엔지니어가 가르치는 파이썬 장고 웹프로그래밍

Model Form(모델 폼)에 대해 알아보기

form.save() 부분이 안돼요

작성

·

284

1

Internal Server Error: /polls/survey/

Traceback (most recent call last):

File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute

return self.cursor.execute(sql, params)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute

return super().execute(query, params)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

sqlite3.OperationalError: no such table: polls_survey

The above exception was the direct cause of the following exception:

Traceback (most recent call last):

File "/opt/homebrew/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner

response = get_response(request)

^^^^^^^^^^^^^^^^^^^^^

File "/opt/homebrew/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in getresponse

response = wrapped_callback(request, callback_args, *callback_kwargs)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/Users/minjiwon/Desktop/py/mysite/polls/views.py", line 98, in survey

form.save()

File "/opt/homebrew/lib/python3.11/site-packages/django/forms/models.py", line 542, in save

self.instance.save()

File "/opt/homebrew/lib/python3.11/site-packages/django/db/models/base.py", line 814, in save

self.save_base(

File "/opt/homebrew/lib/python3.11/site-packages/django/db/models/base.py", line 877, in save_base

updated = self._save_table(

^^^^^^^^^^^^^^^^^

File "/opt/homebrew/lib/python3.11/site-packages/django/db/models/base.py", line 1020, in savetable

results = self._do_insert(

^^^^^^^^^^^^^^^^

File "/opt/homebrew/lib/python3.11/site-packages/django/db/models/base.py", line 1061, in doinsert

return manager._insert(

^^^^^^^^^^^^^^^^

File "/opt/homebrew/lib/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method

return getattr(self.get_queryset(), name)(*args, **kwargs)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/homebrew/lib/python3.11/site-packages/django/db/models/query.py", line 1805, in _insert

return query.get_compiler(using=using).execute_sql(returning_fields)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/homebrew/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1822, in execute_sql

cursor.execute(sql, params)

File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/utils.py", line 102, in execute

return super().execute(sql, params)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/utils.py", line 67, in execute

return self._execute_with_wrappers(

^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/utils.py", line 80, in executewith_wrappers

return executor(sql, params, many, context)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/utils.py", line 84, in _execute

with self.db.wrap_database_errors:

File "/opt/homebrew/lib/python3.11/site-packages/django/db/utils.py", line 91, in exit

raise dj_exc_value.with_traceback(traceback) from exc_value

File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute

return self.cursor.execute(sql, params)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute

return super().execute(query, params)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

django.db.utils.OperationalError: no such table: polls_survey

[05/Jul/2023 05:30:34] "POST /polls/survey/ HTTP/1.1" 500 141650

 

이렇게 뜨면서 안되고 어드민에서 survey 들어가는 것도 안되는데 makemigrations 다시 해봐도 똑같아요

답변 1

0

미쿡엔지니어님의 프로필 이미지
미쿡엔지니어
지식공유자

안녕하세요 Zmann님,

일단 질문 잘 하셨구요. 제가 보기에는 마지막에 있는 에러 문구가 안되는 이유인 것 같습니다.

django.db.utils.OperationalError: no such table: polls_survey

에러 그대로 현재 polls_survey라는 테이블이 데이타베이스에 없는 점이 문제입니다.

혹시 migration은 하셨나요?

python manage.py migrate

위에 커맨드를 해보시면 migrations의 내용들이 데이타베이스에 적용되는 것을 보실 수 있을 듯 합니다.

자세한 내용은 https://docs.djangoproject.com/en/4.2/topics/migrations/ 있습니다.

Zmann님의 프로필 이미지
Zmann

작성한 질문수

질문하기