Rafał Tomaszewski
Rafał Tomaszewski

Reputation: 1

Why i can't change my database objects in django/sqlite?

I got the error below when I try to see my products in Django admin panel. In my products models I have "models.DecimalField" I think it is important. Django error discription

At line 34 of base.py is a function:

def decoder(conv_func):

"""
Convert bytestrings from Python's sqlite3 interface to a regular string.
"""
return lambda s: conv_func(s.decode())

More information: InvalidOperation at /admin/products/products/



Request Method: GET
Request URL: http://127.0.0.1:8000/admin/products/products/

Django Version: 2.0.7
Python Version: 3.5.2
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'products',
 'pages']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
  35.             response = get_response(request)

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
  128.                 response = self.process_exception_by_middleware(e, request)

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
  126.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/contrib/admin/options.py" in wrapper
  575.                 return self.admin_site.admin_view(view)(*args, **kwargs)

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/contrib/admin/sites.py" in inner
  223.             return view(request, *args, **kwargs)

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/utils/decorators.py" in _wrapper
  62.             return bound_func(*args, **kwargs)

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/utils/decorators.py" in bound_func
  58.                 return func.__get__(self, type(self))(*args2, **kwargs2)

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/contrib/admin/options.py" in changelist_view
  1708.             selection_note=_('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)},

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/db/models/query.py" in __len__
  254.         self._fetch_all()

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/db/models/query.py" in _fetch_all
  1179.             self._result_cache = list(self._iterable_class(self))

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/db/models/query.py" in __iter__
  53.         results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/db/models/sql/compiler.py" in execute_sql
  1101.                 return list(result)

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/db/models/sql/compiler.py" in cursor_iter
  1462.         for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/db/models/sql/compiler.py" in <lambda>
  1462.         for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/db/utils.py" in inner
  96.                 return func(*args, **kwargs)

File "/home/rt7/Pulpit/django_yt/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py" in <lambda>
  34.     return lambda s: conv_func(s.decode())

Exception Type: InvalidOperation at /admin/products/products/
Exception Value: [<class 'decimal.ConversionSyntax'>]

products/admin.py

from django.contrib import admin

from .models import Products

admin.site.register(Products)

Upvotes: 0

Views: 151

Answers (1)

Rafał Tomaszewski
Rafał Tomaszewski

Reputation: 1

I found my mistake. In my first version of models I added product with price as a string value.

class Products(models.Model):
    title       = models.CharField(max_length=120)
    description = models.TextField()
    price       = models.CharField(max_length=120)

Then I changed this class and made price value as DecimalField()

class Products(models.Model):
    title       = models.CharField(max_length=120)
    description = models.TextField()
    price       = models.DecimalField(null=False, decimal_places=0, max_digits=1000)

In my case that was easy to solve becouse i added only one product with price as a string. I used "DB Browser for SQLite" and changed value manualy.

Upvotes: 0

Related Questions