python - 在Django-mssql中运行syncdb时SQL插入编译器错误

标签 python django sql-server-2005 django-mssql

这是在 Microsoft SQL Server 2005 上。 Python 2.7。 Django 1.4

Django-MSSQL 已安装并连接到数据库。

我可以读取表格,但不能插入或更新它们。通过 django 在空数据库上的教程,我得到了这一点:

# Save the object into the database. You have to call save() explicitly.
>>> p.save()

调用 save() 后我得到这个 error message (也有报道):

Creating tables ...
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 459, in execute_manager
utility.execute()
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 232, in execute
output = self.handle(*args, **options)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 371, in handle
return self.handle_noargs(**options)
File "C:\Python26\lib\site-packages\django\core\management\commands\syncdb.py", line 110, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "C:\Python26\lib\site-packages\django\core\management\sql.py", line 189, in emit_post_sync_signal
interactive=interactive, db=db)
File "C:\Python26\lib\site-packages\django\dispatch\dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
File "C:\Python26\lib\site-packages\django\contrib\auth\management\__init__.py", line 35, in create_permissions
ctype = ContentType.objects.get_for_model(klass)
File "C:\Python26\lib\site-packages\django\contrib\contenttypes\models.py", line 42, in get_for_model
defaults = {'name': smart_unicode(opts.verbose_name_raw)},
File "C:\Python26\lib\site-packages\django\db\models\manager.py", line 134, in get_or_create
return self.get_query_set().get_or_create(**kwargs)
File "C:\Python26\lib\site-packages\django\db\models\query.py", line 449, in get_or_create
obj.save(force_insert=True, using=self.db)
File "C:\Python26\lib\site-packages\django\db\models\base.py", line 463, in save
self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "C:\Python26\lib\site-packages\django\db\models\base.py", line 551, in save_base
result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "C:\Python26\lib\site-packages\django\db\models\manager.py", line 203, in _insert
return insert_query(self.model, objs, fields, **kwargs)
File "C:\Python26\lib\site-packages\django\db\models\query.py", line 1576, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Python26\lib\site-packages\django\db\models\sql\compiler.py", line 909, in execute_sql
for sql, params in self.as_sql():
File "C:\Python26\lib\site-packages\django_mssql-1.0.1-py2.6.egg\sqlserver_ado\compiler.py", line 207, in as_sql
sql, params = super(SQLInsertCompiler, self).as_sql(*args, **kwargs)
ValueError: need more than 1 value to unpack

更新:我回滚到 Django 1.3,这个错误就消失了。我怀疑 Django 在 1.4 中处理用户和身份验证的方式发生了变化。当我有机会时,我会查看源代码并尝试修补。

最佳答案

django-mssql v1.1 添加了对 Django 1.4 的支持

pip install django-mssql>=1.1

关于python - 在Django-mssql中运行syncdb时SQL插入编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10134822/

相关文章:

c# - 从代码测试存储过程是否为 "Parse"/"Compile"

python - __str__ 和 __repr__ 的区别?

python - 检查 pandas 数据框列中的值是否存在于另一列中。 isin 方法不起作用

python - 如何创建一个 'urlpattern' 且数量不定的 'named regex groups'

django docker-compose --> memcached 不工作

sql - 仅获取 Y 列中最靠近 X 列的行

python - 在 Azure 中运行多个 Python 脚本(使用 Docker?)

python - 你如何使用 easy_install 安装 django 旧版本?

python - 如何在 django 中为表单创建下拉框?

sql - 如何从 DATETIME 列获取日期?