gpt4 book ai didi

django - 错误绑定(bind)参数 2 - 可能是不受支持的类型

转载 作者:行者123 更新时间:2023-12-04 06:15:02 25 4
gpt4 key购买 nike

下面的代码来自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.

引发错误绑定(bind)参数 2 的原因 - 可能是不受支持的类型。在代码中?

我是新手,不知道如何解决这个异常?谢谢。

最佳答案

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

我的解决方案 : 我在我的 settings/dev.py 中使用下面的配置

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}

在我的模型中,我有:
class MyModel(models.Model):
parameter0 = django.contrib.postgres.fields.JSONField()

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

关于django - 错误绑定(bind)参数 2 - 可能是不受支持的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7359415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com