I am building class models using Django and mongodb is connected to my server successfully.
When I create a new object in “ChatRoom” model, I can create and save new data and everything is snyc to my database.
However, when I tried to create a object in “Profile” model, I got this error.
DatabaseError at /admin/chat/profile/add/
No exception message supplied
| Request Method: | POST |
|---|---|
| Request URL: | http://127.0.0.1:8000/admin/chat/profile/add/ |
| Django Version: | 4.1.9 |
| Exception Type: | DatabaseError |
| Exception Location: | C:\Users\Vaibhav\Desktop\chatroom\chatApplication\env\Lib\site-packages\djongo\cursor.py, line 81, in fetchone |
| Raised during: | django.contrib.admin.options.add_view |
| Python Executable: | C:\Users\Vaibhav\Desktop\chatroom\chatApplication\env\Scripts\python.exe |
| Python Version: | 3.11.3 |
| Python Path: | [‘C:\Users\Vaibhav\Desktop\chatroom\chatApplication’, ‘C:\Python311\python311.zip’, ‘C:\Python311\DLLs’, ‘C:\Python311\Lib’, ‘C:\Python311’, ‘C:\Users\Vaibhav\Desktop\chatroom\chatApplication\env’, ‘C:\Users\Vaibhav\Desktop\chatroom\chatApplication\env\Lib\site-packages’] |
This is my code.
models.py
from django.db import models
from django.contrib.auth.models import User
import uuid
class Profile(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
unique_id = models.UUIDField(default=uuid.uuid4, primary_key=True)
image = models.FileField(upload_to='profile_pic', null=True)
last_text = models.CharField(max_length=100)
online_status = models.BooleanField(default=False)
last_seen = models.DateTimeField(auto_now=True)
class ChatRoom(models.Model):
name = models.CharField(max_length=100, null=True)
slug = models.SlugField(unique=True, null=True)
room_id = models.CharField(max_length=64)
How can I fix this database error? please let me know if u need more information