错误绑定参数2 - 可能不受支持的类型

时间:2011-09-09 09:09:52

标签: django

以下代码来自views.py

def register(request):
    if request.method=="POST":
    form = RegisterForm (request.POST)
    if form.is_valid():
        success = True
        first_name = form.cleaned_data[ 'first_name']
        last_name = form.cleaned_data[ 'last_name']
        username  = form.cleaned_data[ 'username' ]
        password = form.cleaned_data[ 'password']
        confirm_password = form.cleaned_data[ 'confirm_password']
        address  = form.cleaned_data[ 'address' ]
        form.save()
        return HttpResponseRedirect("/success/")
    else:
        form=RegisterForm()
    return render_to_response('homepage/register.html',
        {'form':form,},context_instance=RequestContext(request))

错误追溯:

  Traceback:
  File "/usr/local/lib/python2.6/site-packages/django/core/handlers/base.py" in 
  get_response 
  92. response = callback(request, *callback_args, **callback_kwargs)   
  File "/root/Desktop/blog/blog/../blog/apps/homepage/views.py" in register
  99. form.save()
  File "/usr/local/lib/python2.6/site-packages/django/forms/models.py" in save
  407. fail_message, commit, exclude=self._meta.exclude)
  File "/usr/local/lib/python2.6/site-packages/django/forms/models.py" in save_instance
  78.         instance.save()
  File "/usr/local/lib/python2.6/site-packages/django/db/models/base.py" in save
  410.         self.save_base(force_insert=force_insert, force_update=force_update)
  File "/usr/local/lib/python2.6/site-packages/django/db/models/base.py" in save_base
  495.                     result = manager._insert(values, return_id=update_pk)
  File "/usr/local/lib/python2.6/site-packages/django/db/models/manager.py" in _insert
  177.         return insert_query(self.model, values, **kwargs)
  File "/usr/local/lib/python2.6/site-packages/django/db/models/query.py" in          
  insert_query
  1087.     return query.execute_sql(return_id)
  File "/usr/local/lib/python2.6/site-packages/django/db/models/sql/subqueries.py" in 
  execute_sql
  320.         cursor = super(InsertQuery, self).execute_sql(None)
  File "/usr/local/lib/python2.6/site-packages/django/db/models/sql/query.py" in 
  execute_sql
  2369.         cursor.execute(sql, params)
  File "/usr/local/lib/python2.6/site-packages/django/db/backends/util.py" in execute
  19.             return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.6/site-packages/django/db/backends/sqlite3/base.py" in 
  execute
  193.         return Database.Cursor.execute(self, query, params)
  Exception Type: InterfaceError at /register/
  Exception Value: Error binding parameter 2 - probably unsupported type.

什么抛出错误绑定参数2 - 可能是不受支持的类型。在代码?

我是新手我不知道怎么解决这个例外?感谢。

1 个答案:

答案 0 :(得分:1)

我知道这是一个老问题,但我遇到了类似的问题,并想分享我的发现。

我的解决方案:我在settings/dev.py

中使用了以下配置
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': ':memory:',
    }
}

在我的模型中,我有:

class MyModel(models.Model):
    parameter0 = django.contrib.postgres.fields.JSONField()

然后,当Django尝试用parameter0插入MyModel(parameter0=some_value).save()时,数据库不支持它。