我无法打开本地服务器。我做了待办事项清单

时间:2019-10-14 09:36:24

标签: python django localhost

当前状态

我简化了“待办事项清单”。我从日语网站复制并粘贴。 这些过程进展顺利,但是当我设置本地服务器时,发生了此错误

python manage.py runserver 8080


Performing system checks...

System check identified no issues (0 silenced).

You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
October 14, 2019 - 18:23:49
Django version 2.2.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8080/
Quit the server with CTRL-BREAK.
C:\Users\kazu\Anaconda3\lib\site-packages\django\views\generic\list.py:88: UnorderedObjectListWarning: Pagination may yield inconsistent results with an unordered object_list: <class 'todo.models.Todo'> QuerySet.
  allow_empty_first_page=allow_empty_first_page, **kwargs)
Internal Server Error: /todo/list/
Traceback (most recent call last):
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\backends\sqlite3\base.py", line 383, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: todo_todo

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

Traceback (most recent call last):
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\views\generic\base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\views\generic\base.py", line 97, in dispatch
    return handler(request, *args, **kwargs)
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\views\generic\list.py", line 157, in get
    context = self.get_context_data()
  File "C:\Users\kazu\Anaconda3\lib\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 "C:\Users\kazu\Anaconda3\lib\site-packages\django\views\generic\list.py", line 69, in paginate_queryset
    page = paginator.page(page_number)
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\core\paginator.py", line 70, in page
    number = self.validate_number(number)
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\core\paginator.py", line 48, in validate_number
    if number > self.num_pages:
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\utils\functional.py", line 80, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\core\paginator.py", line 97, in num_pages
    if self.count == 0 and not self.allow_empty_first_page:
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\utils\functional.py", line 80, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\core\paginator.py", line 91, in count
    return c()
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\models\query.py", line 392, in count
    return self.query.get_count(using=self.db)
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\models\sql\query.py", line 504, in get_count
    number = obj.get_aggregation(using, ['__count'])['__count']
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\models\sql\query.py", line 489, in get_aggregation
    result = compiler.execute_sql(SINGLE)
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 1100, in execute_sql
    cursor.execute(sql, params)
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 99, in execute
    return super().execute(sql, params)
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 67, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 76, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\kazu\Anaconda3\lib\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 table: todo_todo
[14/Oct/2019 18:25:18] "GET /todo/list/ HTTP/1.1" 500 165625
Not Found: /favicon.ico
[14/Oct/2019 18:25:19] "GET /favicon.ico HTTP/1.1" 404 2077

我没有发现有错误的文件。因此,如果您知道哪个文件有错误,可以告诉我吗?我会将代码发布到文件中。

1 个答案:

答案 0 :(得分:0)

sqlite3.OperationalError: no such table: todo_todo,

这意味着您的数据库-todo中没有名为 db.sqlite3 的表。在django中进行更改时,您需要进行迁移,这是model中的标准步骤,然后通过上述@YevhenKuzmovych注释中提到的命令在数据库中创建表。

  1. python manage.py makemigrations

然后

  1. python manage.py migrate
  

养成习惯,在对包含模型类的model.py进行任何更改时,始终运行这两个命令