Skip to content
Advertisement

django.db.utils.OperationalError: no such function: JSON_VALID

I literally don’t know how to deal with it and how it is happening I am getting this error when I run python manage.py migrate, migrations were without an error.

Mycode

models.py

from django.db import models
import uuid
from django.contrib.auth.models import User
# Create your models here.

class Orders(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    products = models.CharField(max_length=6000)
    zip_code = models.IntegerField()
    address = models.CharField(max_length=600)
    city = models.CharField(max_length=600)
    state = models.CharField(max_length=600)
    email = models.EmailField()
    date = models.DateTimeField(auto_now=True)

views.py

from django.core import serializers

@login_required
def checkout(request):
    user = User.objects.get(pk=request.user.id)
    cartItems = Cart.objects.filter(user=user)  
    cartJson = serializers.serialize('json', cartItems)
    print(cartJson)
    price = 0
    for cartItem in cartItems:
        price = price + cartItem.cart_item.price * cartItem.quantity
    message = ""
    if request.method=="POST":
        products = request.POST['products']
        email = request.POST['email']
        address = request.POST['address'] 
        city = request.POST['city']
        state = request.POST['state']
        zip_code = request.POST['zip']
        order = Orders(products=products, user=user, email=email, address=address, city=city,
                       state=state, zip_code=zip_code)
        order.save()
        message = "Order Successfully Placed"
        cartItems.delete()
    context = {
        'message' : message,
        'cartItems' : cartItems,
        'price' : price
    }
    return render(request, 'ecom/checkout.html', context)

full command line error

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, ecom, sessions
Running migrations:
  Applying ecom.0009_orders...Traceback (most recent call last):
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbbackendsutils.py", line 82, in _execute
    return self.cursor.execute(sql)
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbbackendssqlite3base.py", line 411, in execute
    return Database.Cursor.execute(self, query)
sqlite3.OperationalError: no such function: JSON_VALID

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangocoremanagement__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangocoremanagement__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangocoremanagementbase.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangocoremanagementbase.py", line 371, in execute
    output = self.handle(*args, **options)
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangocoremanagementbase.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangocoremanagementcommandsmigrate.py", line 243, in handle
    post_migrate_state = executor.migrate(
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbmigrationsexecutor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbmigrationsexecutor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbmigrationsexecutor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbmigrationsmigration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbmigrationsoperationsmodels.py", line 92, in database_forwards
    schema_editor.create_model(model)
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbbackendsbaseschema.py", line 324, in create_model
    self.execute(sql, params or None)
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbbackendsbaseschema.py", line 142, in execute
    cursor.execute(sql, params)
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbbackendsutils.py", line 98, in execute
    return super().execute(sql, params)
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbbackendsutils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbbackendsutils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbbackendsutils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbutils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbbackendsutils.py", line 82, in _execute
    return self.cursor.execute(sql)
  File "C:UsersAdminAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbbackendssqlite3base.py", line 411, in execute
    return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: no such function: JSON_VALID

If you are able to solve the issue then answer and along with it also tell me any issue in my code or any bad practice in my code If at all answerer 😂! need any more code please ask just solve the issue

Thank You

Advertisement

Answer

In my case the issue was with the file 009_orders.py under migrations folder
There was a JSON field ('products', models.JSONField())
Which is not supported by Sqlite3 (which I am using)

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement