堆栈溢出。
#models.py
class Tag(models.Model):
title = models.CharField(max_length=300, unique=True)
slug = models.SlugField(max_length=300, blank=True, null=True, unique=True)
objects = TagManager()
def generate_token(self):
self.slug = get_random_string(length=15)
return self.slug
def save(self, *args, **kwargs):
if self.slug is None:
self.generate_token()
super().save(*args, **kwargs)
class Item(models.Model):
seller = models.ForeignKey(User,related_name='seller', on_delete=models.CASCADE)
#the following lines are the problem lines
tag = models.ManyToManyField(Tag, related_name='tag', blank=True)
slug = models.SlugField(max_length=30, blank=True, null=True, unique=True)
objects = ItemManager()
def generate_token(self):
self.slug = get_random_string(length=15)
return self.slug
def save(self, *args, **kwargs):
if self.slug is None:
self.generate_token()
super().save(*args, **kwargs)
和
详细信息:失败行包含(18,Item Name在这里,这是描述,40.00,items/pattern.png,lXBjgo70QIrI8aF,1,null)。
这是完整的回溯
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/item/item/add/
Django Version: 3.2.6
Python Version: 3.9.6
Installed Applications:
['django.contrib.admin',
'django.contrib.sites',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'cameloapp',
'user',
'item',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
'allauth.socialaccount.providers.twitter']
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 "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
The above exception (null value in column "tag_id" of relation "item_item" violates not-null constraint
DETAIL: Failing row contains (18, Item Name Here, This is the description, 40.00, items/pattern.png, lXBjgo70QIrI8aF, 1, null).
) was the direct cause of the following exception:
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\admin\options.py", line 616, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\admin\sites.py", line 232, in inner
return view(request, *args, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\admin\options.py", line 1657, in add_view
return self.changeform_view(request, None, form_url, extra_context)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\admin\options.py", line 1540, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\admin\options.py", line 1586, in _changeform_view
self.save_model(request, new_object, form, not add)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\admin\options.py", line 1099, in save_model
obj.save()
File "C:\Users\User\camelo\cameloapp\item\models.py", line 104, in save
super().save(*args, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\base.py", line 726, in save
self.save_base(using=using, force_insert=force_insert,
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\base.py", line 763, in save_base
updated = self._save_table(
File "C:\Users\User\AppData\Local\Programs\Python\Python39\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\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\base.py", line 906, in _do_insert
return manager._insert(
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\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\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\sql\compiler.py", line 1416, in execute_sql
cursor.execute(sql, params)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\utils.py", line 98, in execute
return super().execute(sql, params)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\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\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
Exception Type: IntegrityError at /admin/item/item/add/
Exception Value: null value in column "tag_id" of relation "item_item" violates not-null constraint
DETAIL: Failing row contains (18, Item Name Here, This is the description, 40.00, items/pattern.png, lXBjgo70QIrI8aF, 1, null).
提前谢谢你
我认为问题是你没有把模型类和self发送到super方法
更改保存方法
super(Tag, self).save(*args, **kwargs)
super(Item, self).save(*args, **kwargs)
我在postgresql中创建了一个存储过程,如下所示: 是->的类型 我在插入时得到如下错误:
当我打印申请者的技能列表时,我有以下内容: 下面是一张表格,列出了申请人和技能之间的联系: 但是当我试图保存申请者时,我有这样一个提示:失败的行包含(23,null,null,499)。有人能给我解释一下吗?我正在使用jpa注释开发一个spring应用程序。
这是我的代码,但当我尝试插入另一个“analise”时,num\u cedula,num\u doente,data\u analise为NULL,它会给我这个错误(“错误:num\u cedula”列中的NULL值违反了非NULL约束细节:失败的行包含(32,Ortopedia,NULL,NULL,NULL,NULL,2019-12-02,glicemia,176,Instituicao1)。S
我正在使用带有Postgres数据库连接的JBPM6.5.0Final。当我尝试从jbpm-workbench容器开始时,将显示以下错误: 而且还 提前道谢。
照明\database\queryexception SQLSTATE[23000]:完整性约束违反:19 NOT NULL约束失败:users.password(SQL:插入“users”(“name”、“email”、“username”、“updated_at”、“created_at”)值(MADHUP KUMAR,Chandrashivam99@gmail.com,Vansh123,20
我正在使用JBPM6.5.0Final和Postgres数据库连接。当我尝试通过jbpm-workbench容器启动时,会出现以下错误: 而且还有 提前谢了。