DatabaseError at /admin/core/profile/add/ No exception message supplied

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

2 Likes

Hi Vaibhav! Were you able to fix the issue? I’m stuck with a similar error.

class CompetitionRommList(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
is_private = models.BooleanField(default=False)
about = models.TextField()
amount = models.FloatField(default=10000)

if your model class content any other reference object like forging key and you try to direct stock hole reference object than djongo throw the error. Solution is try to store object values rather than hole object.