我試圖保存我的模型窗體。 Django重新啓動InternalError: current transaction is aborted, commands ignored until end of transaction block
Django模型保存方法:錯誤:在「args」處或附近的語法錯誤
這是執行INSERT
sql-query 時出現的一個問題,它由Django生成。它看起來像:
INSERT INTO "myapp_mymodel" ("title", ...) VALUES ("Test", ...) RETURNING "catalog_ad"."id"; args=("title", ...)
我試圖在PgAdmin中執行此查詢。它返回了這個錯誤:
ERROR: syntax error at or near "args"
什麼可能是錯的?
UPD:這裏是tracback爲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:
我的模型具有overwrited保存方法:
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())。
在'args'之前需要';'嗎?查詢是由django生成還是由您執行? – Rohan 2012-08-03 15:06:56
這個查詢是由django生成的。這是個問題。等一下。我會添加追溯 – 2012-08-03 15:08:18
一些代碼的觀點,模型也將是有用的。 – Rohan 2012-08-03 15:09:43