项目场景:
提示:这里简述项目相关背景:
Django-3.2.14 +django-simpleui-2022.7.29+openGauss3.0.0 删除按钮出现:“ psycopg2.errors.NotNullViolation: null value in column “change_message” violates not-null constraint” 的报错处理
问题描述
Django-3.2.14 +django-simpleui-2022.7.29+openGauss3.0.0 点击删除按钮出现:“ psycopg2.errors.NotNullViolation: null value in column “change_message” violates not-null constraint” 报错, 详细报错如下:
Internal Server Error: /admin/testapp/py_funtion/ Traceback (most recent call last): File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/db/backends/utils.py”, line 84, in _execute return self.cursor.execute(sql, params) psycopg2.errors.NotNullViolation: null value in column “change_message” violates not-null constraint DETAIL: Failing row contains (23, 2022-09-08 14:18:55.752364+00, TEST, py_funtion object (TEST), 3, null, 9, 7).
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/core/handlers/exception.py”, line 47, in inner response = get_response(request) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/core/handlers/base.py”, line 181, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/contrib/admin/options.py”, line 616, in wrapper return self.admin_site.admin_view(view)(*args, **kwargs) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/utils/decorators.py”, line 130, in _wrapped_view response = view_func(request, *args, **kwargs) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/views/decorators/cache.py”, line 44, in _wrapped_view_func response = view_func(request, *args, **kwargs) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/contrib/admin/sites.py”, line 232, in inner return view(request, *args, **kwargs) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/utils/decorators.py”, line 43, in _wrapper return bound_method(*args, **kwargs) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/utils/decorators.py”, line 130, in _wrapped_view response = view_func(request, *args, **kwargs) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/contrib/admin/options.py”, line 1739, in changelist_view response = self.response_action(request, queryset=cl.get_queryset(request)) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/contrib/admin/options.py”, line 1408, in response_action response = func(self, request, queryset) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/contrib/admin/actions.py”, line 44, in delete_selected modeladmin.log_deletion(request, obj, obj_display) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/contrib/admin/options.py”, line 849, in log_deletion action_flag=DELETION, File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/contrib/admin/models.py”, line 35, in log_action change_message=change_message, File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/db/models/manager.py”, line 85, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/db/models/query.py”, line 453, in create obj.save(force_insert=True, using=self.db) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/db/models/base.py”, line 740, in save force_update=force_update, update_fields=update_fields) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/db/models/base.py”, line 778, in save_base force_update, using, update_fields, File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/db/models/base.py”, line 881, in _save_table results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/db/models/base.py”, line 921, in _do_insert using=using, raw=raw, File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/db/models/manager.py”, line 85, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/db/models/query.py”, line 1270, in _insert return query.get_compiler(using=using).execute_sql(returning_fields) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/db/models/sql/compiler.py”, line 1416, in execute_sql cursor.execute(sql, params) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/db/backends/utils.py”, line 98, in execute return super().execute(sql, params) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/db/backends/utils.py”, line 66, in execute return self._execute_with_wrappers(sql, params, many=False, executor=self._execute) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/db/backends/utils.py”, line 75, in _execute_with_wrappers return executor(sql, params, many, context) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/db/backends/utils.py”, line 84, in _execute return self.cursor.execute(sql, params) File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/db/utils.py”, line 90, in exit raise dj_exc_value.with_traceback(traceback) from exc_value File “/usr/local/lib/python3.7/site-packages/Django-3.2.14-py3.7.egg/django/db/backends/utils.py”, line 84, in _execute return self.cursor.execute(sql, params) django.db.utils.IntegrityError: null value in column “change_message” violates not-null constraint DETAIL: Failing row contains (23, 2022-09-08 14:18:55.752364+00, TEST, py_funtion object (TEST), 3, null, 9, 7).
原因分析:
注意到如下报错: null value in column “change_message” violates not-null constraint 初步判断是 django-simpleui 管理的表结构有问题, 在 openGauss 适配过程中的问题, 检查发现表 django_admin_log 的 change_message 字段是 NOT NULL
解决方案:
登录 openGauss 数据库, 修改表 django_admin_log 的 change_message 字段 将 NOT NULL 修改为 NULL, 重新启动 python3 manage.py runserver 问题解决。
|