我正在尝试保存我的模型表单。姜戈回归InternalError: current transaction is aborted, commands ignored until end of transaction block
这是执行Django 生成的INSERT
sql-query时出现的问题。看起来像:
INSERT INTO "myapp_mymodel" ("title", ...) VALUES ("Test", ...) RETURNING "catalog_ad"."id"; args=("title", ...)
我试图在 PgAdmin 中执行这个查询。它返回了这个错误:
ERROR: syntax error at or near "args"
有什么问题?
UPD:这是 InternalError 的回溯:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/<Path to my app>/views.py" in master
115. ad = form.save()
File "/Library/Python/2.7/site-packages/django/forms/models.py" in save
364. fail_message, commit, construct=False)
File "/Library/Python/2.7/site-packages/django/forms/models.py" in save_instance
86. instance.save()
File "<Path to my app>/models.py" in save
145. super(Ad, self).save(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in save
463. self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in save_base
551. result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "/Library/Python/2.7/site-packages/django/db/models/manager.py" in _insert
203. return insert_query(self.model, objs, fields, **kwargs)
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in insert_query
1576. return query.get_compiler(using=using).execute_sql(return_id)
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
910. cursor.execute(sql, params)
UPD2:
我的模型覆盖了保存方法:
def save(self, *args, **kwargs):
self.title = self.model.brand.name + " " + self.model.name
super(Ad, self).save(*args, **kwargs)
数据由使用的视图ModelForm
处理(从 POST 获取数据)。保存前已验证表单 (form.is_valid())。