【发布时间】:2020-05-15 10:46:20
【问题描述】:
我正在尝试向 django 管理面板内的组添加一些现有权限。但它显示以下错误,我不知道它为什么会发生。
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...
^
【问题讨论】:
标签: django python-3.x postgresql