ajmaln / DRF-Chat

Live Chat using Django REST Framework
126 stars 49 forks source link

no such table: chat_message #1

Closed NightHawk451 closed 6 years ago

NightHawk451 commented 6 years ago

I copied your project, pipped the requirements and ran it as is. I made two users. When one user tries to chat with the other (they click on the new user) you get the following error message:

Environment:

Request Method: GET Request URL: http://127.0.0.1:8000/chat/2/1

Django Version: 2.0 Python Version: 3.6.4 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'widget_tweaks', 'rest_framework', 'chat'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Template error:
In template C:\Users\Starlord\Dev\ChatApp2\DRF-Chat\templates\chat\index.html, error at line 0
   no such table: chat_message
   1 : {% load staticfiles %}
   2 :   <!DOCTYPE html>
   3 :   <html>
   4 :     <head>
   5 :       <!--Import Google Icon Font-->
   6 :         <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
   7 :         <!--Import materialize.css-->
   8 :         <link type="text/css" rel="stylesheet" href="{% static 'css/materialize.min.css' %}"  media="screen,projection"/>
   9 :         <link type="text/css" rel="stylesheet" href="{% static 'css/style.css' %}"  media="screen,projection"/>
   10 : 

Traceback:

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\db\backends\utils.py" in _execute

  1. return self.cursor.execute(sql, params)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\db\backends\sqlite3\base.py" in execute

  1. return Database.Cursor.execute(self, query, params)

The above exception (no such table: chat_message) was the direct cause of the following exception:

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\core\handlers\exception.py" in inner

  1. response = get_response(request)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\core\handlers\base.py" in _get_response

  1. response = self.process_exception_by_middleware(e, request)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\core\handlers\base.py" in _get_response

  1. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\Starlord\Dev\ChatApp2\DRF-Chat\chat\views.py" in message_view

  1. Message.objects.filter(sender_id=receiver, receiver_id=sender)})

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\shortcuts.py" in render

  1. content = loader.render_to_string(template_name, context, request, using=using)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\loader.py" in render_to_string

  1. return template.render(context, request)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\backends\django.py" in render

  1. return self.template.render(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\base.py" in render

  1. return self._render(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\base.py" in _render

  1. return self.nodelist.render(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\base.py" in render

  1. bit = node.render_annotated(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\base.py" in render_annotated

  1. return self.render(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\loader_tags.py" in render

  1. return compiled_parent._render(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\base.py" in _render

  1. return self.nodelist.render(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\base.py" in render

  1. bit = node.render_annotated(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\base.py" in render_annotated

  1. return self.render(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\loader_tags.py" in render

  1. return compiled_parent._render(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\base.py" in _render

  1. return self.nodelist.render(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\base.py" in render

  1. bit = node.render_annotated(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\base.py" in render_annotated

  1. return self.render(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\loader_tags.py" in render

  1. result = block.nodelist.render(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\base.py" in render

  1. bit = node.render_annotated(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\base.py" in render_annotated

  1. return self.render(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\loader_tags.py" in render

  1. result = block.nodelist.render(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\base.py" in render

  1. bit = node.render_annotated(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\base.py" in render_annotated

  1. return self.render(context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\template\defaulttags.py" in render

  1. len_values = len(values)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\db\models\query.py" in len

  1. self._fetch_all()

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\db\models\query.py" in _fetch_all

  1. self._result_cache = list(self._iterable_class(self))

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\db\models\query.py" in iter

  1. results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql

  1. cursor.execute(sql, params)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\db\backends\utils.py" in execute

  1. return super().execute(sql, params)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\db\backends\utils.py" in execute

  1. return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\db\backends\utils.py" in _execute_with_wrappers

  1. return executor(sql, params, many, context)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\db\backends\utils.py" in _execute

  1. return self.cursor.execute(sql, params)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\db\utils.py" in exit

  1. raise dj_exc_value.with_traceback(traceback) from exc_value

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\db\backends\utils.py" in _execute

  1. return self.cursor.execute(sql, params)

File "C:\Users\Starlord\Dev\ChatApp2\lib\site-packages\django\db\backends\sqlite3\base.py" in execute

  1. return Database.Cursor.execute(self, query, params)

Exception Type: OperationalError at /chat/2/1 Exception Value: no such table: chat_message

NightHawk451 commented 6 years ago

The above can be fixed with the below code:

python manage.py migrate --run-syncdb