Programming Error: "user_id of relation APP_MODEL does not exist" - django

I've set User as a foreign key on my Video model. I am using the default django auth User model, and have managed to create a user using the serializer and view that I set up for it. The problem is that whenever I try to create a video entry I hit the title error.
I've tried clearing the database, redoing the migrations, but there aren't any migrations for the app that handles the user serializer.
The Model
from django.contrib.auth.models import User
class Video(models.Model):
user = models.ForeignKey(
User,
on_delete=models.CASCADE,
null=True
)
map_marker = models.ForeignKey(MapMarker, on_delete=models.CASCADE)
created = models.DateTimeField()
ip_addr = models.TextField()
file_id = models.TextField()
class Meta:
ordering = ('created',)
Full traceback:
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/videos/
Django Version: 2.2.1
Python Version: 3.7.2
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'userbase',
'trickspot',
'profanity']
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 "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\db\backends\utils.py" in _execute
84. return self.cursor.execute(sql, params)
The above exception (column "user_id" of relation "trickspot_video" does not exist
LINE 1: INSERT INTO "trickspot_video" ("user_id", "map_marker_id", "...
^
) was the direct cause of the following exception:
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\core\handlers\exception.py" in inner
34. response = get_response(request)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\core\handlers\base.py" in _get_response
115. response = self.process_exception_by_middleware(e, request)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\core\handlers\base.py" in _get_response
113. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\views\decorators\csrf.py" in wrapped_view
54. return view_func(*args, **kwargs)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\rest_framework\viewsets.py" in view
116. return self.dispatch(request, *args, **kwargs)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\rest_framework\views.py" in dispatch
495. response = self.handle_exception(exc)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\rest_framework\views.py" in handle_exception
455. self.raise_uncaught_exception(exc)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\rest_framework\views.py" in dispatch
492. response = handler(request, *args, **kwargs)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\rest_framework\mixins.py" in create
21. self.perform_create(serializer)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\rest_framework\mixins.py" in perform_create
26. serializer.save()
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\rest_framework\serializers.py" in save
214. self.instance = self.create(validated_data)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\rest_framework\serializers.py" in create
943. instance = ModelClass._default_manager.create(**validated_data)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\db\models\manager.py" in manager_method
82. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\db\models\query.py" in create
422. obj.save(force_insert=True, using=self.db)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\db\models\base.py" in save
741. force_update=force_update, update_fields=update_fields)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\db\models\base.py" in save_base
779. force_update, using, update_fields,
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\db\models\base.py" in _save_table
870. result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\db\models\base.py" in _do_insert
908. using=using, raw=raw)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\db\models\manager.py" in manager_method
82. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\db\models\query.py" in _insert
1186. return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql
1335. cursor.execute(sql, params)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\db\backends\utils.py" in execute
99. return super().execute(sql, params)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\db\backends\utils.py" in execute
67. return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\db\backends\utils.py" in _execute_with_wrappers
76. return executor(sql, params, many, context)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\db\backends\utils.py" in _execute
84. return self.cursor.execute(sql, params)
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\db\utils.py" in __exit__
89. raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\Zeph\.virtualenvs\SK8M8_API-LRdA6z3-\lib\site-packages\django\db\backends\utils.py" in _execute
84. return self.cursor.execute(sql, params)
Exception Type: ProgrammingError at /videos/
Exception Value: column "user_id" of relation "trickspot_video" does not exist
LINE 1: INSERT INTO "trickspot_video" ("user_id", "map_marker_id", "...
^
The entry should be saved with the key of the user I selected on the API view.

Something got broken along the way and dropping the DB and starting again fixed the problem.
Thanks

Related

django.db.utils.ProgrammingError: relation "xx" does not exist

I was trying to add a new column to a database table by using make migrations on Django, bit didn't work and I got some weird errors. Following advice on another SO post I used DROP TABLE to delete the table and start again.
The problem is, now when I try to migrate the table it doesn't appear in my PostgreSQL database. When I check make migrations I don't get any changes to migrate suggesting it is synced. I have also run: python3 manage.py migrate --run-syncdb and still getting no luck.
I'd appreciate any help.
class UserVenue(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
venue = models.ForeignKey(mapCafes, on_delete=models.PROTECT)
user_list = models.ForeignKey(UserList, on_delete=models.CASCADE)
class Meta:
unique_together = ['user_list','venue']
For some reason I can still see the table in Django Admin but then get this error:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/testingland/uservenue/
Django Version: 3.1.7
Python Version: 3.8.5
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'testingland',
'rest_framework',
'bootstrap_modal_forms']
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 (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
The above exception (relation "testingland_uservenue" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "testingland_uservenue"
^
) was the direct cause of the following exception:
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/contrib/admin/options.py", line 614, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/contrib/admin/sites.py", line 233, in inner
return view(request, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/contrib/admin/options.py", line 1693, in changelist_view
cl = self.get_changelist_instance(request)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/contrib/admin/options.py", line 735, in get_changelist_instance
return ChangeList(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/contrib/admin/views/main.py", line 100, in __init__
self.get_results(request)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/contrib/admin/views/main.py", line 235, in get_results
result_count = paginator.count
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/paginator.py", line 94, in count
return c()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/models/query.py", line 411, in count
return self.query.get_count(using=self.db)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/models/sql/query.py", line 515, in get_count
number = obj.get_aggregation(using, ['__count'])['__count']
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/models/sql/query.py", line 500, in get_aggregation
result = compiler.execute_sql(SINGLE)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1156, in execute_sql
cursor.execute(sql, params)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/backends/utils.py", line 98, in execute
return super().execute(sql, params)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
Exception Type: ProgrammingError at /admin/testingland/uservenue/
Exception Value: relation "testingland_uservenue" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "testingland_uservenue"
^
Try one of the following or do all:
Delete all files in the migrations folder
Delete/Drop Table django_migrations
Delete/Drop Table error
Then rerun your migrations & migrate
(this way worked for me)

Error when trying to add permissions to a group in django admin panel

I am trying to add a few existing permissions to the group inside the django admin panel. But its showing the below error and I haven't got a clue why its happening.
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/auth/group/4/change/
Django Version: 3.0.6
Python Version: 3.8.2
Installed Applications:
['exams.apps.ExamsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'bootstrap4']
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 (most recent call last):
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
The above exception (syntax error at or near "ON"
LINE 1: ...ons" ("group_id", "permission_id") VALUES (4, 20) ON CONFLIC...
^
) was the direct cause of the following exception:
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/contrib/admin/options.py", line 607, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/contrib/admin/sites.py", line 231, in inner
return view(request, *args, **kwargs)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/contrib/admin/options.py", line 1641, in change_view
return self.changeform_view(request, object_id, form_url, extra_context)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/contrib/admin/options.py", line 1522, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/contrib/admin/options.py", line 1566, in _changeform_view
self.save_related(request, form, formsets, not add)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/contrib/admin/options.py", line 1107, in save_related
form.save_m2m()
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/forms/models.py", line 442, in _save_m2m
f.save_form_data(self.instance, cleaned_data[f.name])
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/db/models/fields/related.py", line 1618, in save_form_data
getattr(instance, self.attname).set(data)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py", line 1008, in set
self.add(*new_objs, through_defaults=through_defaults)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py", line 944, in add
self._add_items(
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py", line 1123, in _add_items
self.through._default_manager.using(db).bulk_create([
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/db/models/query.py", line 492, in bulk_create
returned_columns = self._batched_insert(
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/db/models/query.py", line 1230, in _batched_insert
self._insert(item, fields=fields, using=self.db, ignore_conflicts=ignore_conflicts)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/db/models/query.py", line 1204, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1391, in execute_sql
cursor.execute(sql, params)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/defiant/Projects/Python3.8/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
Exception Type: ProgrammingError at /admin/auth/group/4/change/
Exception Value: syntax error at or near "ON"
LINE 1: ...ons" ("group_id", "permission_id") VALUES (4, 20) ON CONFLIC...
^
It had something to do with the postgres version I was using. Used the latest docker image for hosting the db and the error was gone.

Attempt to write a readonly SQLite database in Django

I have implemented my simple Django applications on server, but my forms for users can not save anything.
My database settings looks like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
My error which template receives looks like this:
nvironment:
Request Method: POST
Request URL: http://68.183.76.239/wyniki-wyszukiwania/konta-bankowe/
Django Version: 2.2.2
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',
'app',
'django_filters',
'crispy_forms',
'django_select2']
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/app/lib/python3.5/site-packages/django/db/backends/utils.py" in _execute
84. return self.cursor.execute(sql, params)
File "/home/app/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py" in execute
383. return Database.Cursor.execute(self, query, params)
The above exception (attempt to write a readonly database) was the direct cause of the following exception:
File "/home/app/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/home/app/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
115. response = self.process_exception_by_middleware(e, request)
File "/home/app/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
113. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/app/app/app/views.py" in search_results_account
149. product_broken_form.save()
File "/home/app/lib/python3.5/site-packages/django/forms/models.py" in save
458. self.instance.save()
File "/home/app/lib/python3.5/site-packages/django/db/models/base.py" in save
741. force_update=force_update, update_fields=update_fields)
File "/home/app/lib/python3.5/site-packages/django/db/models/base.py" in save_base
779. force_update, using, update_fields,
File "/home/app/lib/python3.5/site-packages/django/db/models/base.py" in _save_table
870. result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/app/lib/python3.5/site-packages/django/db/models/base.py" in _do_insert
908. using=using, raw=raw)
File "/home/app/lib/python3.5/site-packages/django/db/models/manager.py" in manager_method
82. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/app/lib/python3.5/site-packages/django/db/models/query.py" in _insert
1186. return query.get_compiler(using=using).execute_sql(return_id)
File "/home/app/lib/python3.5/site-packages/django/db/models/sql/compiler.py" in execute_sql
1335. cursor.execute(sql, params)
File "/home/app/lib/python3.5/site-packages/django/db/backends/utils.py" in execute
99. return super().execute(sql, params)
File "/home/app/lib/python3.5/site-packages/django/db/backends/utils.py" in execute
67. return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/app/lib/python3.5/site-packages/django/db/backends/utils.py" in _execute_with_wrappers
76. return executor(sql, params, many, context)
File "/home/app/lib/python3.5/site-packages/django/db/backends/utils.py" in _execute
84. return self.cursor.execute(sql, params)
File "/home/app/lib/python3.5/site-packages/django/db/utils.py" in __exit__
89. raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/app/lib/python3.5/site-packages/django/db/backends/utils.py" in _execute
84. return self.cursor.execute(sql, params)
File "/home/app/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py" in execute
383. return Database.Cursor.execute(self, query, params)
Exception Type: OperationalError at /wyniki-wyszukiwania/konta-bankowe/
Exception Value: attempt to write a readonly database
How can I add changes to get rid of an error? I found similar answers on Stack Overflow, but I did not find information on how to allow everyone to write changes to SQLite (to make the error disappear).
The first place that I would look for is whether or not the user who is running the Django app has write permissions on db.sqlite file.

django custom user's model and UserAdmin - Programmin error while adding a new user

I'm having some troubles while using a custom user model and the admin
# models.py
from django.db import models
from django.contrib.auth.models import AbstractUser
class Employee(AbstractUser):
class Meta:
verbose_name = 'Employee'
verbose_name_plural = 'Employees'
# settings.py
AUTH_USER_MODEL = 'myapp.Employee'
# admin.py
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from myapp.models import Employee
admin.site.register(Employee, UserAdmin)
Well when I try to add a new user, it trows me this error:
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8050/admin/chaos/employee/add/
Django Version: 1.7.1
Python Version: 2.7.6
Installed Applications:
['admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'reversion',
'mptt',
'imperavi',
'django_mptt_admin',
'document',
'chaos']
Installed Middleware:
['django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
584. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
105. response = view_func(request, *args, **kwargs)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
52. response = view_func(request, *args, **kwargs)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
204. return view(request, *args, **kwargs)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
29. return bound_func(*args, **kwargs)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
76. return view(request, *args, **kwargs)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
25. return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
29. return bound_func(*args, **kwargs)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
105. response = view_func(request, *args, **kwargs)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
25. return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/transaction.py" in inner
394. return func(*args, **kwargs)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/contrib/auth/admin.py" in add_view
121. extra_context)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in add_view
1454. return self.changeform_view(request, None, form_url, extra_context)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
29. return bound_func(*args, **kwargs)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
105. response = view_func(request, *args, **kwargs)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
25. return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/transaction.py" in inner
394. return func(*args, **kwargs)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in changeform_view
1397. if form.is_valid():
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/forms/forms.py" in is_valid
162. return self.is_bound and not bool(self.errors)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/forms/forms.py" in errors
154. self.full_clean()
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/forms/forms.py" in full_clean
353. self._clean_fields()
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/forms/forms.py" in _clean_fields
371. value = getattr(self, 'clean_%s' % name)()
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/contrib/auth/forms.py" in clean_username
101. User._default_manager.get(username=username)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/models/manager.py" in manager_method
92. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/models/query.py" in get
351. num = len(clone)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/models/query.py" in __len__
122. self._fetch_all()
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/models/query.py" in _fetch_all
966. self._result_cache = list(self.iterator())
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/models/query.py" in iterator
265. for row in compiler.results_iter():
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in results_iter
700. for rows in self.execute_sql(MULTI):
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
786. cursor.execute(sql, params)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
81. return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
65. return self.cursor.execute(sql, params)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/utils.py" in __exit__
94. six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
65. return self.cursor.execute(sql, params)
Exception Type: ProgrammingError at /admin/chaos/employee/add/
Exception Value: relation "auth_user" does not exist
LINE 1: ...user"."is_active", "auth_user"."date_joined" FROM "auth_user...
Anybody experienced the same thing and any hint to solve it?
I had a suspect that I need also to subclass the UserCreationForm and UserChangeForm used by the original UserAdmin, but if it is the correct way, I honestly don't see the advantages of using a custom user model rather that create a one-to-one model (e.g. Profile) to extend the original User.
Thanks
Luca
Good day, Luke!
Please, look at django docs: https://docs.djangoproject.com/en/dev/topics/auth/customizing/
Just check, what model you are using: CustomUser or AbstractBaseUser.
As I can see, now it's AbstractUser.

Integrity Error and Operational Error Django 1.6.6

I am just starting out to develop a Django Blog, and am following this youtube tutorial - https://www.youtube.com/watch?v=7rgph8en0Jc&spfreload=1
I am using Django 1.6.6.
Everytime I try to add Entry in Admin, I get this error. Thanks for your help!
Environment:
Django Version: 1.6.6
Python Version: 2.7.8
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'niceblog',
'django_markdown')
Installed Middleware:
('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 "C:\Users\user\desktop\firstblog\lib\site-packages\django\core\handlers\base.py"
in get_response
112. response = wrapped_callback(request, *callback_args, >**callback_kwargs)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\contrib\admin\options.py"
in wrapper
450. return self.admin_site.admin_view(view)(*args, **kwargs)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\utils\decorators.py"
in _wrapped_view
99. response = view_func(request, *args, **kwargs)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\views\decorators\cache.py"
in _wrapped_view_func
52. response = view_func(request, *args, **kwargs)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\contrib\admin\sites.py"
in inner
198. return view(request, *args, **kwargs)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\utils\decorators.py"
in _wrapper
29. return bound_func(*args, **kwargs)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\utils\decorators.py"
in _wrapped_view
99. response = view_func(request, *args, **kwargs)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\utils\decorators.py"
in bound_func
25. return func(self, *args2, **kwargs2)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\transaction.py"
in inner
371. return func(*args, **kwargs)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\contrib\admin\options.py"
in add_view
1149. self.save_model(request, new_object, form, False)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\contrib\admin\options.py"
in save_model
878. obj.save()
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\base.py"
in save
545. force_update=force_update, update_fields=update_fields)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\base.py"
in save_base
573. updated = self._save_table(raw, cls, force_insert, force_update, using, >update_fields)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\base.py"
in _save_table
654. result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\base.py"
in _do_insert
687. using=using, raw=raw)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\manager.py"
in _insert
232. return insert_query(self.model, objs, fields, **kwargs)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\query.py"
in insert_query
1514. return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\sql\compiler.py"
in execute_sql
903. cursor.execute(sql, params)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\backends\util.py"
in execute
69. return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\backends\util.py"
in execute
53. return self.cursor.execute(sql, params)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\utils.py"
in exit
99. six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\backends\util.py"
in execute
53. return self.cursor.execute(sql, params)
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\backends\sqlite3\base.py"
in execute
452. return Database.Cursor.execute(self, query, params)
Exception Type: IntegrityError at /admin/niceblog/entry/add/
Exception Value: niceblog_entry.slug may not be NULL
Everytime I try to edit Entry in Admin, it throws this error
Environment:
Django Version: 1.6.6 Python Version: 2.7.8 Installed Applications:
('django.contrib.admin', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.staticfiles', 'niceblog',
'django_markdown') Installed Middleware:
('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
"C:\Users\user\desktop\firstblog\lib\site-packages\django\core\handlers\base.py"
in get_response
112. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\contrib\admin\options.py"
in wrapper
450. return self.admin_site.admin_view(view)(*args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\utils\decorators.py"
in _wrapped_view
99. response = view_func(request, *args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\views\decorators\cache.py"
in _wrapped_view_func
52. response = view_func(request, *args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\contrib\admin\sites.py"
in inner
198. return view(request, *args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\utils\decorators.py"
in _wrapper
29. return bound_func(*args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\utils\decorators.py"
in _wrapped_view
99. response = view_func(request, *args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\utils\decorators.py"
in bound_func
25. return func(self, *args2, **kwargs2) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\transaction.py"
in inner
371. return func(*args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\contrib\admin\options.py"
in change_view
1255. form = ModelForm(instance=obj) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\forms\models.py"
in init
315. object_data = model_to_dict(instance, opts.fields, opts.exclude) File
"C:\Users\user\desktop\firstblog\lib\site-packages\django\forms\models.py"
in model_to_dict
141. data[f.name] = list(f.value_from_object(instance).values_list('pk', flat=True)) File
"C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\query.py"
in iter
96. self._fetch_all() File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\query.py"
in _fetch_all
857. self._result_cache = list(self.iterator()) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\query.py"
in iterator
1068. for row in self.query.get_compiler(self.db).results_iter(): File
"C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\sql\compiler.py"
in results_iter
713. for rows in self.execute_sql(MULTI): File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\sql\compiler.py"
in execute_sql
786. cursor.execute(sql, params) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\backends\util.py"
in execute
69. return super(CursorDebugWrapper, self).execute(sql, params) File
"C:\Users\user\desktop\firstblog\lib\site-packages\django\db\backends\util.py"
in execute
53. return self.cursor.execute(sql, params) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\utils.py"
in exit
99. six.reraise(dj_exc_type, dj_exc_value, traceback) File
"C:\Users\user\desktop\firstblog\lib\site-packages\django\db\backends\util.py"
in execute
53. return self.cursor.execute(sql, params) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\backends\sqlite3\base.py"
in execute
452. return Database.Cursor.execute(self, query, params)
Exception Type: OperationalError at /admin/niceblog/entry/2/ Exception
Value: no such table: niceblog_entry_tags
models.py file --->
class Tag(models.Model):
slug = models.SlugField(max_length=200, unique=True)
def __unicode__(self):
return self.slug
class Entry(models.Model):
title = models.CharField(max_length=200)
body = models.TextField()
publish = models.BooleanField(default=True)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
tags = models.ManyToManyField(Tag)
def __unicode__(self):
return self.title
class Meta:
verbose_name = "Blog Entry"
verbose_name_plural = "Blog Entries"
ordering = ['-created']
admin.py file --->
class EntryAdmin(MarkdownModelAdmin):
list_display = ("title", "created")
admin.site.register(Entry, EntryAdmin)
admin.site.register(Tag)
I guess, Entry.tags was added after table creation.
If it's possible to upgrade django to 1.7 then you can use built-in migrations.
Firstable reset your app to actual db schema, i.e. remove tags field, then:
# Create initial migrations
$ python manage.py makemigrations your_app
# Migrate
$ python manage.py migrate your_app
# Add your tags field. Repeat
$ python manage.py makemigrations your_app
$ python manage.py migrate your_app
If you want to stay on django 1.6, use South. It's pretty much the same:
# Create initial migrations
$ python manage.py schemamigration your_app intial --init
# Migrate
$ python manage.py migrate your_app --fake
# Add your tags field. Create migration
$ python manage.py schemamigration your_app add_tags --auto
$ python manage.py migrate your_app