报错来自django-oscar从低版本向高版本迁移的时候发生的.
完整报错如下:
Traceback (most recent call last):
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 383, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such column: catalogue_product.is_public
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python3.7/contextlib.py", line 74, in inner
return func(*args, **kwds)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/views/generic/base.py", line 97, in dispatch
return handler(request, *args, **kwargs)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/oscar/apps/catalogue/views.py", line 136, in get
return super().get(request, *args, **kwargs)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/views/generic/base.py", line 158, in get
context = self.get_context_data(**kwargs)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/oscar/apps/catalogue/views.py", line 145, in get_context_data
self.context_object_name)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/oscar/apps/catalogue/search_handlers.py", line 106, in get_search_context_data
context = self.get_context_data(object_list=self.object_list)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/views/generic/list.py", line 119, in get_context_data
paginator, page, queryset, is_paginated = self.paginate_queryset(queryset, page_size)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/views/generic/list.py", line 69, in paginate_queryset
page = paginator.page(page_number)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/paginator.py", line 70, in page
number = self.validate_number(number)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/paginator.py", line 48, in validate_number
if number > self.num_pages:
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/paginator.py", line 97, in num_pages
if self.count == 0 and not self.allow_empty_first_page:
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/paginator.py", line 91, in count
return c()
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/db/models/query.py", line 392, in count
return self.query.get_count(using=self.db)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/db/models/sql/query.py", line 504, in get_count
number = obj.get_aggregation(using, ['__count'])['__count']
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/db/models/sql/query.py", line 489, in get_aggregation
result = compiler.execute_sql(SINGLE)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1133, in execute_sql
cursor.execute(sql, params)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 99, in execute
return super().execute(sql, params)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 383, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such column: catalogue_product.is_public
[07/Mar/2020 17:17:13] "GET /catalogue/ HTTP/1.1" 500 229440
解决方案:
稍微复杂,你需要首先定义一个
is_public的字段
然后赋值
然后才能选择NN(not null)
你并不能一开始在新建字段的时候,
就选择NN,DB Browser fro SQLite会报错