You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 3, 2020. It is now read-only.
Hi. I made models.py by watching your video, but I'm not sure how to solve this problem.
First of all, when I access to 127.0.0.1:8000/admin/chat/chat/add,
It shows
django.db.utils.OperationalError: no such table: chat_contact
This is my models.py, and I migrated and deleted this models.py for several times.
from django.contrib.auth import get_user_model
from django.db import models
User = get_user_model()
# Create your models here.
class Contact(models.Model):
user = models.ForeignKey(User, related_name='friends', on_delete=models.CASCADE)
friends = models.ManyToManyField('self', blank=True)
def __str__(self):
return self.user.username
class Message(models.Model):
contact = models.ForeignKey(Contact, related_name='messages', on_delete=models.CASCADE)
content = models.TextField()
timestamp = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.contact.user.username
class Chat(models.Model):
participants = models.ManyToManyField(Contact, related_name='chats')
messages = models.ManyToManyField(Message, blank=True)
def last_10_messages(self):
return self.messages.objects.order_by('-timestamp').all()[:10]
def __str__(self):
return "{}".format(self.pk)
Template error:
In template E:\Django\Django_Channels\New_Channels\lib\site-packages\django\contrib\admin\templates\admin\includes\fieldset.html, error at line 19
no such table: chat_contact
9 : {% for field in line %}
10 : <div{% if not line.fields|length_is:'1' %} class="fieldBox{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}"{% elif field.is_checkbox %} class="checkbox-row"{% endif %}>
11 : {% if not line.fields|length_is:'1' and not field.is_readonly %}{{ field.errors }}{% endif %}
12 : {% if field.is_checkbox %}
13 : {{ field.field }}{{ field.label_tag }}
14 : {% else %}
15 : {{ field.label_tag }}
16 : {% if field.is_readonly %}
17 :
Traceback (most recent call last):
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\db\backends\sqlite3\base.py", line 396, in execute
return Database.Cursor.execute(self, query, params)
The above exception (no such table: chat_contact) was the direct cause of the following exception:
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\core\handlers\base.py", line 145, in _get_response
response = self.process_exception_by_middleware(e, request)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\core\handlers\base.py", line 143, in _get_response
response = response.render()
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\response.py", line 105, in render
self.content = self.rendered_content
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\response.py", line 83, in rendered_content
return template.render(context, self._request)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 171, in render
return self._render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\defaulttags.py", line 209, in render
nodelist.append(node.render_annotated(context))
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\loader_tags.py", line 188, in render
return template.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 173, in render
return self._render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\defaulttags.py", line 209, in render
nodelist.append(node.render_annotated(context))
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\defaulttags.py", line 209, in render
nodelist.append(node.render_annotated(context))
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\defaulttags.py", line 309, in render
return nodelist.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\defaulttags.py", line 309, in render
return nodelist.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 992, in render
return render_value_in_context(output, context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\template\base.py", line 971, in render_value_in_context
value = str(value)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\utils\html.py", line 373, in
klass.str = lambda self: mark_safe(klass_str(self))
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\forms\boundfield.py", line 33, in str
return self.as_widget()
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\forms\boundfield.py", line 96, in as_widget
renderer=self.form.renderer,
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\forms\widgets.py", line 241, in render
context = self.get_context(name, value, attrs)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\contrib\admin\widgets.py", line 288, in get_context
'rendered_widget': self.widget.render(name, value, attrs),
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\forms\widgets.py", line 241, in render
context = self.get_context(name, value, attrs)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\forms\widgets.py", line 678, in get_context
context = super().get_context(name, value, attrs)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\forms\widgets.py", line 639, in get_context
context['widget']['optgroups'] = self.optgroups(name, context['widget']['value'], attrs)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\forms\widgets.py", line 587, in optgroups
for index, (option_value, option_label) in enumerate(self.choices):
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\forms\models.py", line 1140, in iter
for obj in queryset:
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\db\models\query.py", line 346, in _iterator
yield from self._iterable_class(self, chunked_fetch=use_chunked_fetch, chunk_size=chunk_size)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\db\models\query.py", line 57, in iter
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\db\models\sql\compiler.py", line 1151, in execute_sql
cursor.execute(sql, params)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\db\backends\utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\db\utils.py", line 90, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "E:\Django\Django_Channels\New_Channels\lib\site-packages\django\db\backends\sqlite3\base.py", line 396, in execute
return Database.Cursor.execute(self, query, params)
Exception Type: OperationalError at /admin/chat/chat/add/
Exception Value: no such table: chat_contact
How should I solve this??
The text was updated successfully, but these errors were encountered:
Hi. I made models.py by watching your video, but I'm not sure how to solve this problem.
First of all, when I access to 127.0.0.1:8000/admin/chat/chat/add,
It shows
This is my models.py, and I migrated and deleted this models.py for several times.
And this is the Error Occurs.
How should I solve this??
The text was updated successfully, but these errors were encountered: