Djangoの管理ページでモデルのデータを追加するとエラーが表示されますが、エラーの原因をあまり説明していません。このエラーの原因となっている何Django admin TypeError:バッファオブジェクトが必要です
直接データベースにデータを追加するには...だけで正常に動作しますか?
モデル:
class Partner(models.Model):
name = models.CharField(max_length=70)
link = models.CharField(max_length=125)
available = models.BinaryField(default=1)
price = models.IntegerField(default=0)
def __str__(self):
return self.name
エラー:
Request Method: POST
Request URL: http://localhost:8000/admin/myapp/partner/add/
Django Version: 1.9.5
Python Version: 2.7.11
Installed Applications:
['myapp.apps.MyappConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles']
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.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python27\lib\site-packages\django\contrib\admin\options.py" in wrapper
541. return self.admin_site.admin_view(view)(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\utils\decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\contrib\admin\sites.py" in inner
244. return view(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\contrib\admin\options.py" in add_view
1437. return self.changeform_view(request, None, form_url, extra_context)
File "C:\Python27\lib\site-packages\django\utils\decorators.py" in _wrapper
67. return bound_func(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\utils\decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\utils\decorators.py" in bound_func
63. return func.__get__(self, type(self))(*args2, **kwargs2)
File "C:\Python27\lib\site-packages\django\utils\decorators.py" in inner
184. return func(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\contrib\admin\options.py" in changeform_view
1378. self.save_model(request, new_object, form, not add)
File "C:\Python27\lib\site-packages\django\contrib\admin\options.py" in save_model
991. obj.save()
File "C:\Python27\lib\site-packages\django\db\models\base.py" in save
708. force_update=force_update, update_fields=update_fields)
File "C:\Python27\lib\site-packages\django\db\models\base.py" in save_base
736. updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "C:\Python27\lib\site-packages\django\db\models\base.py" in _save_table
820. result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "C:\Python27\lib\site-packages\django\db\models\base.py" in _do_insert
859. using=using, raw=raw)
File "C:\Python27\lib\site-packages\django\db\models\manager.py" in manager_method
122. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py" in _insert
1039. return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql
1059. for sql, params in self.as_sql():
File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py" in as_sql
1019. for obj in self.query.objs
File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py" in prepare_value
958. value = field.get_db_prep_save(value, connection=self.connection)
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py" in get_db_prep_save
728. prepared=False)
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py" in get_db_prep_value
2353. return connection.Database.Binary(value)
Exception Type: TypeError at /admin/myapp/partner/add/
Exception Value: buffer object expected
私はあなたが望むものは 'available = models.BooleanField(デフォルト= True)'だと思います。 –