Django Polls App: OperationalError: attempt to write a read only database - python

I was going through the tutorial on the Django website.
I got this error while trying to create a Choice Object.
>>> q.choice_set.create(choice_text='Not much', votes=0)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Library/Python/2.7/site-packages/Django-1.7.8-py2.7.egg/django/db/models/fields/related.py", line 714, in create
return super(RelatedManager, self.db_manager(db)).create(**kwargs)
File "/Library/Python/2.7/site-packages/Django-1.7.8-py2.7.egg/django/db/models/manager.py", line 92, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Library/Python/2.7/site-packages/Django-1.7.8-py2.7.egg/django/db/models/query.py", line 372, in create
obj.save(force_insert=True, using=self.db)
File "/Library/Python/2.7/site-packages/Django-1.7.8-py2.7.egg/django/db/models/base.py", line 589, in save
force_update=force_update, update_fields=update_fields)
File "/Library/Python/2.7/site-packages/Django-1.7.8-py2.7.egg/django/db/models/base.py", line 617, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/Library/Python/2.7/site-packages/Django-1.7.8-py2.7.egg/django/db/models/base.py", line 698, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/Library/Python/2.7/site-packages/Django-1.7.8-py2.7.egg/django/db/models/base.py", line 731, in _do_insert
using=using, raw=raw)
File "/Library/Python/2.7/site-packages/Django-1.7.8-py2.7.egg/django/db/models/manager.py", line 92, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Library/Python/2.7/site-packages/Django-1.7.8-py2.7.egg/django/db/models/query.py", line 921, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/Library/Python/2.7/site-packages/Django-1.7.8-py2.7.egg/django/db/models/sql/compiler.py", line 921, in execute_sql
cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/Django-1.7.8-py2.7.egg/django/db/backends/utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Library/Python/2.7/site-packages/Django-1.7.8-py2.7.egg/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/Django-1.7.8-py2.7.egg/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Library/Python/2.7/site-packages/Django-1.7.8-py2.7.egg/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/Django-1.7.8-py2.7.egg/django/db/backends/sqlite3/base.py", line 485, in execute
return Database.Cursor.execute(self, query, params)
OperationalError: attempt to write a readonly database
>>>
I dont understand what seems to be the problem. I tried changing the permissions for the "db.sqlite3" file to 777.
Thank you in advance.

You have to change permissions to the directory that database file is in too.

If running on Mac OS X, make sure to prepend the command with sudo (in the command line).

Related

Created objects are not save through cmd in django python

from sabin.models import Task
>>> Task.objects.all()
<QuerySet []>
>>> t=Task(title="dhiraj")
t=Task(title="dhiraj")
t.save()
models.py file
from django.db import models
class Task(models.Model):
title=models.CharField(max_length=200)
completed=models.BooleanField(default=False)
created_at=models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
Error says
Traceback (most recent call last):
File "C:\Users\Dhiraj Subedi\ero\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Dhiraj Subedi\ero\lib\site-packages\django\db\backends\sqlite3\base.py", line 423, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: table sabin_task has no column named title
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Users\Dhiraj Subedi\ero\lib\site-packages\django\db\models\base.py", line 726, in save
self.save_base(using=using, force_insert=force_insert,
File "C:\Users\Dhiraj Subedi\ero\lib\site-packages\django\db\models\base.py", line 763, in save_base
updated = self._save_table(
File "C:\Users\Dhiraj Subedi\ero\lib\site-packages\django\db\models\base.py", line 868, in _save_table
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File "C:\Users\Dhiraj Subedi\ero\lib\site-packages\django\db\models\base.py", line 906, in _do_insert
return manager._insert(
File "C:\Users\Dhiraj Subedi\ero\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\Dhiraj Subedi\ero\lib\site-packages\django\db\models\query.py", line 1270, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "C:\Users\Dhiraj Subedi\ero\lib\site-packages\django\db\models\sql\compiler.py", line 1410, in execute_sql
cursor.execute(sql, params)
File "C:\Users\Dhiraj Subedi\ero\lib\site-packages\django\db\backends\utils.py", line 98, in execute
return super().execute(sql, params)
File "C:\Users\Dhiraj Subedi\ero\lib\site-packages\django\db\backends\utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\Dhiraj Subedi\ero\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\Dhiraj Subedi\ero\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Dhiraj Subedi\ero\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\Dhiraj Subedi\ero\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Dhiraj Subedi\ero\lib\site-packages\django\db\backends\sqlite3\base.py", line 423, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: table sabin_task has no column named title

Throws "IntegrityError: duplicate key value violates unique constraint" while publishing a page in Django-cms

Recently I migrated my local django + django-cms site to production server using following methods:
moved code to production server and populated db schema using makemigration and migrate commands
I exported the data using Pycharm's inbuilt database tool via "Dump data to File(s)" > "SQL-Insert-Statements.sql.groovy", the exported file had only insert statements and no other sql statement.
I copy pasted and executed these statements in query tool window using pgAdmin 4
I executed sql statements for reset sequences which I got from "python manage.py sqlsequencereset ..." command
Now after doing all this the website is working fine but on the admin side I can edit the page and it keeps the changes in database but throws error when I click on "publish page changes" button.
Here is the error:
django.db.utils.IntegrityError: duplicate key value violates unique constraint "cms_cmsplugin_path_4917bb44_uniq"
DETAIL: Key (path)=(0007) already exists.
Complete error stack:
[15/Jul/2020 21:13:40] "POST /en/admin/cms/page/45/en/publish/ HTTP/1.1" 500 25121
Internal Server Error: /en/admin/cms/page/45/en/publish/
Traceback (most recent call last):
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "cms_cmsplugin_path_4917bb44_uniq"
DETAIL: Key (path)=(0007) already exists.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/john/project1/env/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/john/project1/env/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/john/project1/env/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/john/project1/env/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/john/project1/env/lib/python3.6/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/john/project1/env/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 223, in inner
return view(request, *args, **kwargs)
File "/home/john/project1/env/lib/python3.6/site-packages/django/utils/decorators.py", line 45, in _wrapper
return bound_method(*args, **kwargs)
File "/home/john/project1/env/lib/python3.6/site-packages/django/views/decorators/http.py", line 40, in inner
return func(request, *args, **kwargs)
File "/usr/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/home/john/project1/env/lib/python3.6/site-packages/cms/admin/pageadmin.py", line 1125, in publish_page
all_published = page.publish(language)
File "/home/john/project1/env/lib/python3.6/site-packages/cms/models/pagemodel.py", line 987, in publish
self._copy_contents(public_page, language)
File "/home/john/project1/env/lib/python3.6/site-packages/cms/models/pagemodel.py", line 633, in _copy_contents
placeholder.copy_plugins(target_placeholder, language=language)
File "/home/john/project1/env/lib/python3.6/site-packages/cms/models/placeholdermodel.py", line 580, in copy_plugins
root_plugin=root_plugin,
File "/home/john/project1/env/lib/python3.6/site-packages/cms/utils/plugins.py", line 214, in copy_plugins_to_placeholder
new_plugin = CMSPlugin.add_root(instance=new_plugin)
File "/home/john/project1/env/lib/python3.6/site-packages/treebeard/mp_tree.py", line 625, in add_root
return MP_AddRootHandler(cls, **kwargs).process()
File "/home/john/project1/env/lib/python3.6/site-packages/treebeard/mp_tree.py", line 345, in process
newobj.save()
File "/home/john/project1/env/lib/python3.6/site-packages/djangocms_text_ckeditor/models.py", line 64, in save
super(AbstractText, self).save(*args, **kwargs)
File "/home/john/project1/env/lib/python3.6/site-packages/cms/models/pluginmodel.py", line 270, in save
super(CMSPlugin, self).save(*args, **kwargs)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/models/base.py", line 741, in save
force_update=force_update, update_fields=update_fields)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/models/base.py", line 776, in save_base
parent_inserted = self._save_parents(cls, using, update_fields)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/models/base.py", line 807, in _save_parents
force_insert=parent_inserted,
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/models/base.py", line 870, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/models/base.py", line 908, in _do_insert
using=using, raw=raw)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/models/query.py", line 1186, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1368, in execute_sql
cursor.execute(sql, params)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 99, in execute
return super().execute(sql, params)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: duplicate key value violates unique constraint "cms_cmsplugin_path_4917bb44_uniq"
DETAIL: Key (path)=(0007) already exists.
something similar happened to me after migrating from sqlite to postgresql and I thought it was a problem with this.
But searching I found that it was a Treebeard 4.5 problem.
And the solution that worked for me was to Rollback to version 4.4.
https://github.com/django-cms/django-cms/issues/6980

Hawthorn to Ironwood Migration (Open edX)

I am trying to execute database migration from hawthorn.master to ironwood.master, during MySQL migration, getting the error like this:
Applying content_type_gating.0002_auto_20181119_0959…Traceback (most recent call last):
File “./manage.py”, line 123, in
execute_from_command_line([sys.argv[0]] + django_args)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/management/init.py”, line 364, in execute_from_command_line
utility.execute()
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/management/init.py”, line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/management/base.py”, line 283, in run_from_argv
self.execute(*args, **cmd_options)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/management/base.py”, line 330, in execute
output = self.handle(*args, **options)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py”, line 204, in handle
fake_initial=fake_initial,
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/migrations/executor.py”, line 115, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/migrations/executor.py”, line 145, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/migrations/executor.py”, line 250, in apply_migration
self.recorder.record_applied(migration.app_label, migration.name)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/migrations/recorder.py”, line 73, in record_applied
self.migration_qs.create(app=app, name=name)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/models/query.py”, line 394, in create
obj.save(force_insert=True, using=self.db)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/models/base.py”, line 808, in save
force_update=force_update, update_fields=update_fields)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/models/base.py”, line 838, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/models/base.py”, line 924, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/models/base.py”, line 963, in _do_insert
using=using, raw=raw)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/models/manager.py”, line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/models/query.py”, line 1079, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py”, line 1112, in execute_sql
cursor.execute(sql, params)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/backends/utils.py”, line 64, in execute
return self.cursor.execute(sql, params)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/utils.py”, line 94, in exit
six.reraise(dj_exc_type, dj_exc_value, traceback)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/backends/utils.py”, line 64, in execute
return self.cursor.execute(sql, params)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py”, line 101, in execute
return self.cursor.execute(query, args)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/MySQLdb/cursors.py”, line 205, in execute
self.errorhandler(self, exc, value)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/MySQLdb/connections.py”, line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.IntegrityError: (1062, “Duplicate entry ‘0’ for key ‘PRIMARY’”)
Here is the application link: https://github.com/edx/edx-platform/tree/master/openedx/features/content_type_gating
In addition, this table has no data.
Can anyone help to solve this?

(migrations table) django.db.utils.IntegrityError: null value in column "id" violates not-null constraint

When I run migrate it raises this error. I can't figure out where can be the problem because it is caused by the built-in functionality of adding migration data inside the migrations table.
Running migrations:
Applying matches.0023_auto_20191102_1717...Traceback (most recent call last):
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
psycopg2.IntegrityError: null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, matches, 0023_auto_20191102_1717, 2019-11-02 17:17:38.046421+01).
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 200, in handle
fake_initial=fake_initial,
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/migrations/executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/migrations/executor.py", line 250, in apply_migration
self.recorder.record_applied(migration.app_label, migration.name)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 71, in record_applied
self.migration_qs.create(app=app, name=name)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/models/query.py", line 417, in create
obj.save(force_insert=True, using=self.db)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/models/base.py", line 729, in save
force_update=force_update, update_fields=update_fields)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/models/base.py", line 759, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/models/base.py", line 842, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/models/base.py", line 880, in _do_insert
using=using, raw=raw)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/models/query.py", line 1125, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1285, in execute_sql
cursor.execute(sql, params)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/milano/.virtualenvs/sport_database/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, matches, 0023_auto_20191102_1717, 2019-11-02 17:17:38.046421+01).
Do you know what to do? I can't just drop and recreate the DB.

Stack trace exception while saving object to database Django SQLITE3

I had a really tough time to get fix this issue please help if you know this.
I have a project on django, It contain model with two fields, one is of type foreign key and other one is jsonfield. When it goes to save object in database,
it doesn't get saved instead it throw exception. I don't know what's the issue is. But issue is only specific to sqlite3 database. it is working fine with other databases. I am pasting stack trace and code. it throws exception on this line
student_record_obj.save()
Stack trace:
Internal Server Error: /tableapp/postdata/
Traceback (most recent call last):
File "C:\Python35\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Python35\lib\site-packages\django\db\backends\sqlite3\base.py", line 303, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.InterfaceError: Error binding parameter 1 - probably unsupported type.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Python35\lib\site-packages\django\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "C:\Python35\lib\site-packages\django\db\backends\utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Python35\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Python35\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Python35\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Python35\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Python35\lib\site-packages\django\db\backends\sqlite3\base.py", line 303, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.InterfaceError: Error binding parameter 1 - probably unsupported type.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python35\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "C:\Python35\lib\site-packages\django\core\handlers\base.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Python35\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python35\lib\site-packages\django\contrib\auth\decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File "C:\Users\Jdidi\Documents\Fresh\calendardjangoapp\tableapp\views.py", line 89, in posting_data
student_record_obj.save()
File "C:\Python35\lib\site-packages\django\db\models\base.py", line 729, in save
force_update=force_update, update_fields=update_fields)
File "C:\Python35\lib\site-packages\django\db\models\base.py", line 759, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "C:\Python35\lib\site-packages\django\db\models\base.py", line 842, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "C:\Python35\lib\site-packages\django\db\models\base.py", line 880, in _do_insert
using=using, raw=raw)
File "C:\Python35\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Python35\lib\site-packages\django\db\models\query.py", line 1125, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Python35\lib\site-packages\django\db\models\sql\compiler.py", line 1280, in execute_sql
cursor.execute(sql, params)
File "C:\Python35\lib\site-packages\django\db\backends\utils.py", line 104, in execute
sql = self.db.ops.last_executed_query(self.cursor, sql, params)
File "C:\Python35\lib\site-packages\django\db\backends\sqlite3\operations.py", line 136, in last_executed_query
params = self._quote_params_for_last_executed_query(params)
File "C:\Python35\lib\site-packages\django\db\backends\sqlite3\operations.py", line 125, in _quote_params_for_last_executed_query
return cursor.execute(sql, params).fetchone()
sqlite3.InterfaceError: Error binding parameter 1 - probably unsupported type.
[10/Jul/2018 23:01:32] "POST /tableapp/postdata/ HTTP/1.1" 500 18778
VIEWS.PY:
def posting_data(request):
if request.method == "POST":
response_ls = json.loads(request.POST.get('data', []))
final_ls = []
for dic in response_ls:
if dic and "csrfmiddlewaretoken" not in dic:
final_ls.append(dic)
try:
student_record_obj = StudentRecords.objects.get(user=request.user)
student_record_obj.data = final_ls
except StudentRecords.DoesNotExist:
attrs = {'user':request.user , 'data': final_ls}
student_record_obj = StudentRecords(**attrs)
student_record_obj.save()
return redirect('/tableapp/index')
According to the code above, final_ls variable is a list which is not insertable to database as such.
Dummp it as json string and then save it:
import json
.
.
final_ls = json.dumps(context)
attrs = {'user':request.user , 'data': final_ls}
student_record_obj = StudentRecords(**attrs)
Hope this helps.

Categories