OperationalError at /admin/polls/question/
no such column: polls_question.question_text
とエラーが出ました。
Tracebackでは
The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/Users/XXX/django/django/core/handlers/exception.py", line 35, in inner response = get_response(request) File "/Users/XXX/django/django/core/handlers/base.py", line 130, in _get_response response = self.process_exception_by_middleware(e, request) File "/Users/XXX/django/django/core/handlers/base.py", line 128, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/XXX/django/django/contrib/admin/options.py", line 555, in wrapper return self.admin_site.admin_view(view)(*args, **kwargs) File "/Users/XXX/django/django/utils/decorators.py", line 142, in _wrapped_view response = view_func(request, *args, **kwargs) File "/Users/XXX/django/django/views/decorators/cache.py", line 44, in _wrapped_view_func response = view_func(request, *args, **kwargs) File "/Users/XXX/django/django/contrib/admin/sites.py", line 224, in inner return view(request, *args, **kwargs) File "/Users/XXX/django/django/utils/decorators.py", line 62, in _wrapper return bound_func(*args, **kwargs) File "/Users/XXX/django/django/utils/decorators.py", line 142, in _wrapped_view response = view_func(request, *args, **kwargs) File "/Users/XXX/django/django/utils/decorators.py", line 58, in bound_func return func.__get__(self, type(self))(*args2, **kwargs2) File "/Users/XXX/django/django/contrib/admin/options.py", line 1658, in changelist_view selection_note=_('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)}, File "/Users/XXX/django/django/db/models/query.py", line 223, in __len__ self._fetch_all() File "/Users/XXX/django/django/db/models/query.py", line 1098, in _fetch_all self._result_cache = list(self._iterable_class(self)) File "/Users/XXX/django/django/db/models/query.py", line 53, in __iter__ results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size) File "/Users/XXX/django/django/db/models/sql/compiler.py", line 1001, in execute_sql cursor.execute(sql, params) File "/Users/XXX/django/django/db/backends/utils.py", line 77, in execute return super().execute(sql, params) File "/Users/XXX/django/django/db/backends/utils.py", line 62, in execute return self.cursor.execute(sql, params) File "/Users/XXX/django/django/db/utils.py", line 89, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/Users/XXX/django/django/db/backends/utils.py", line 62, in execute return self.cursor.execute(sql, params) File "/Users/XXX/django/django/db/backends/sqlite3/base.py", line 303, in execute return Database.Cursor.execute(self, query, params) django.db.utils.OperationalError: no such column: polls_question.question_text
pollsアプリの中で
from django.db import models # Create your models here. class Question(models.Model): question_text = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') class Choice(models.Model): question = models.ForeignKey(Question,on_delete=models.CASCADE) choice_text = models.CharField(max_length=200) votes = models.IntegerField(default=0)
とコードを書きました。
そして、
./manage.py makemigrations
とコマンドをうち
(You are trying to add a non-nullable field 'pub_date' to question without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
- Provide a one-off default now (will be set on all existing rows with a null value for this column)
- Quit, and let me add a default in models.py
Select an option: 2 と出たときに2を選択)
さらに
./manage.py migrate
とコマンドをうちました。
そのときに、
Operations to perform: Apply all migrations: admin, auth, contenttypes, polls, sessions Running migrations: No migrations to apply. Your models have changes that are not yet reflected in a migration, and so won't be applied. Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply the
と出ました。
それから
./manage.py runserver
としてサーバーを立ち上げました。
./manage.py makemigrations
と
./manage.py migrate
のmigrateでなぜ2種類のコマンドがあるのかが理解できていませんが、
なぜ/admin/polls/question/ のurlができていないのかわかりません。
どう直せば良いのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。