Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite3.OperationalError: no such table: todolist_todo for webapps -> django #10

Open
jiapei100 opened this issue Feb 21, 2022 · 3 comments

Comments

@jiapei100
Copy link

todoapp git:(master) ✗ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
February 21, 2022 - 07:59:51
Django version 4.0.2, using settings 'todoapp.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Internal Server Error: /
Traceback (most recent call last):
  File "~/.local/lib/python3.8/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "~/.local/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 416, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: todolist_todo

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

Traceback (most recent call last):
  File "~/.local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "~/.local/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "~/Programs/LongerVision/LVT_AI/python-engineer/python-fun/webapps/django/todoapp/todolist/views.py", line 9, in index
    return render(request, "base.html", {"todo_list": todos})
  File "~/.local/lib/python3.8/site-packages/django/shortcuts.py", line 19, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "~/.local/lib/python3.8/site-packages/django/template/loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "~/.local/lib/python3.8/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "~/.local/lib/python3.8/site-packages/django/template/base.py", line 176, in render
    return self._render(context)
  File "~/.local/lib/python3.8/site-packages/django/template/base.py", line 168, in _render
    return self.nodelist.render(context)
  File "~/.local/lib/python3.8/site-packages/django/template/base.py", line 977, in render
    return SafeString(''.join([
  File "~/.local/lib/python3.8/site-packages/django/template/base.py", line 978, in <listcomp>
    node.render_annotated(context) for node in self
  File "~/.local/lib/python3.8/site-packages/django/template/base.py", line 938, in render_annotated
    return self.render(context)
  File "~/.local/lib/python3.8/site-packages/django/template/defaulttags.py", line 174, in render
    len_values = len(values)
  File "~/.local/lib/python3.8/site-packages/django/db/models/query.py", line 262, in __len__
    self._fetch_all()
  File "~/.local/lib/python3.8/site-packages/django/db/models/query.py", line 1354, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "~/.local/lib/python3.8/site-packages/django/db/models/query.py", line 51, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "~/.local/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1202, in execute_sql
    cursor.execute(sql, params)
  File "~/.local/lib/python3.8/site-packages/django/db/backends/utils.py", line 99, in execute
    return super().execute(sql, params)
  File "~/.local/lib/python3.8/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "~/.local/lib/python3.8/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "~/.local/lib/python3.8/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "~/.local/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "~/.local/lib/python3.8/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "~/.local/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 416, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: todolist_todo
[21/Feb/2022 08:00:13] "GET / HTTP/1.1" 500 181849
^C%                                                                                                                                          todoapp git:(master) ✗ 
@stonebig
Copy link
Contributor

stonebig commented May 1, 2022

so for me it works, when I do this :

python manage.py migrate
python manage.py makemigrations todolist
python manage.py migrate todolist
python -m webbrowser -t "http://127.0.0.1:7000/"
python manage.py runserver 7000

image

@spartan124
Copy link

You just need to create your tables...

@coderboy-exe
Copy link

That error is usually caused by a missing database migration after creating a new model.
Simply running the following commands fixes it most of the time:
python3 manage.py makemigrations
python3 manage.py migrate

Now you can restart your server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants