here pic of error
another pic
debug log
DatabaseError at /admin/shop/item/add/
No exception message supplied
Request Method:POSTRequest URL:http://127.0.0.1:8000/admin/shop/item/add/Django Version:4.1.13Exception Type:DatabaseErrorException Location:C:UsersMSIDesktopA Project_Django_thanhducmy_venvLibsite-packagesdjongocursor.py, line 81, in fetchoneRaised during:django.contrib.admin.options.add_viewPython Executable:C:UsersMSIDesktopA Project_Django_thanhducmy_venvScriptspython.exePython Version:3.11.9Python Path:[‘C:\Users\MSI\Desktop\A Project_Django_thanhduc\my_app’, ‘C:\Program ‘ ‘Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\python311.zip’, ‘C:\Program ‘ ‘Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\DLLs’, ‘C:\Program ‘ ‘Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib’, ‘C:\Program ‘ ‘Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0’, ‘C:\Users\MSI\Desktop\A Project_Django_thanhduc\my_venv’, ‘C:\Users\MSI\Desktop\A ‘ ‘Project_Django_thanhduc\my_venv\Lib\site-packages’]Server time:Tue, 21 May 2024 08:33:44 +0000
This is my setting.py database
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'onlineshop',
'ENFORCE_SCHEMA': False,
'CLIENT': {
'host': 'localhost',
'port': 27017,
'authSource': 'admin', # Đảm bảo rằng authSource là đúng
},
'LOGGING': {
'version': 1,
'loggers': {
'djongo': {
'level': 'DEBUG',
'propagate': False,
}
},
},
}
}
Model.py :
from django.db import models
from django.contrib.auth.models import User
class Topic(models.Model):
name = models.CharField(max_length=200)
def __str__(self):
return self.name
class Item(models.Model):
host = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
name = models.CharField(max_length=100)
price = models.DecimalField(max_digits=20, decimal_places=2)
image = models.ImageField(upload_to='items/', null=True, blank=True)
description = models.TextField(null=True, blank=True)
updated = models.DateTimeField(auto_now=True)
created = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ['-created']
def __str__(self):
return f"{self.name} - {self.host.username if self.host else 'No Host'}"
I’m start a project with django and mongodb(with djongo eninge). When I create user in my template(html) i can create item, update, delete, even with superuser.
But when I go to adminstrations(with superuser) and create item to check, (item with host, name, price) and that error appears. That error still occurs with update, but i still can delete item.
That error only occurs with create, update item in adminstrations.
Please find the below codes for reference and help.!
Name: djongo
Version: 1.3.6
Name: Django
Version: 4.1.13
Name: pymongo
Version: 3.12.1