Exception in thread django-main-thread: Traceback (most recent call last):

Viewed 15

I am trying to create a model naming Category, there is no error in the code. But when i run the following code which seems:

There is no error showing on all three files settings.py, admin.py, models.py

    from unittest.util import _MAX_LENGTH
    from django.db import models
    class Category(models.Model):
        tittle=models.CharField(_MAX_LENGTH, 300)
        category_image=models.ImageField(upload_to='images/')

        def _str_(self):
            return self.tittle

but getting the following error on the server. Please help

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Users\Mukesh Bakshi\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "C:\Users\Mukesh Bakshi\AppData\Local\Programs\Python\Python310\lib\threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "D:\Python_Sql\ADMIN\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "D:\Python_Sql\ADMIN\lib\site-packages\django\core\management\commands\runserver.py", line 125, in inner_run
    autoreload.raise_last_exception()
  File "D:\Python_Sql\ADMIN\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception
    raise _exception[1]
  File "D:\Python_Sql\ADMIN\lib\site-packages\django\core\management\__init__.py", line 398, in execute
    autoreload.check_errors(django.setup)()
  File "D:\Python_Sql\ADMIN\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "D:\Python_Sql\ADMIN\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "D:\Python_Sql\ADMIN\lib\site-packages\django\apps\registry.py", line 116, in populate
    app_config.import_models()
  File "D:\Python_Sql\ADMIN\lib\site-packages\django\apps\config.py", line 269, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Users\Mukesh Bakshi\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "D:\Python_Sql\cms_project\cmsmain\models.py", line 3, in <module>
    class Category(models.Model):
  File "D:\Python_Sql\ADMIN\lib\site-packages\django\db\models\base.py", line 192, in __new__
    new_class.add_to_class(obj_name, obj)
  File "D:\Python_Sql\ADMIN\lib\site-packages\django\db\models\base.py", line 369, in add_to_class
    value.contribute_to_class(cls, name)
  File "D:\Python_Sql\ADMIN\lib\site-packages\django\db\models\fields\__init__.py", line 872, in contribute_to_class
    setattr(cls, self.attname, self.descriptor_class(self))
TypeError: attribute name must be string, not 'int'
0 Answers
Related