I have a Django project that does some calculations in Javascript.
I am using Ghost.py to try and incorporate efficient tests of the Javascript calculations into the Django test suite:
from ghost.ext.django.test import GhostTestCase
class CalculationsTest(GhostTestCase):
def setUp(self):
page, resources = self.ghost.open('http://localhost:8081/_test/')
self.assertEqual(page.http_status, 200)
def test_frobnicate(self):
result, e_resources = self.ghost.evaluate('''
frobnicate(test_data, "argument");
''')
self.assertEqual(result, 1.204)
(where frobnicate() is a Javascript function on the test page.
This works very well if I run one test at a time.
If, however, I run django-admin.py test, I get
Traceback (most recent call last):
...
result = self.run_suite(suite)
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/test/runner.py", line 113, in run_suite
).run(suite)
File "/usr/lib64/python2.7/unittest/runner.py", line 151, in run
test(result)
File "/usr/lib64/python2.7/unittest/suite.py", line 70, in __call__
return self.run(*args, **kwds)
File "/usr/lib64/python2.7/unittest/suite.py", line 108, in run
test(result)
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/test/testcases.py", line 184, in __call__
super(SimpleTestCase, self).__call__(result)
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/ghost/test.py", line 53, in __call__
self._post_teardown()
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/test/testcases.py", line 796, in _post_teardown
self._fixture_teardown()
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/test/testcases.py", line 817, in _fixture_teardown
inhibit_post_syncdb=self.available_apps is not None)
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/core/management/__init__.py", line 159, in call_command
return klass.execute(*args, **defaults)
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/core/management/base.py", line 415, in handle
return self.handle_noargs(**options)
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/core/management/commands/flush.py", line 81, in handle_noargs
self.emit_post_syncdb(verbosity, interactive, db)
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/core/management/commands/flush.py", line 101, in emit_post_syncdb
emit_post_sync_signal(set(all_models), verbosity, interactive, database)
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/core/management/sql.py", line 216, in emit_post_sync_signal
interactive=interactive, db=db)
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 185, in send
response = receiver(signal=self, sender=sender, **named)
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 82, in create_permissions
ctype = ContentType.objects.db_manager(db).get_for_model(klass)
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 47, in get_for_model
defaults = {'name': smart_text(opts.verbose_name_raw)},
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/db/models/manager.py", line 154, in get_or_create
return self.get_queryset().get_or_create(**kwargs)
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/db/models/query.py", line 388, in get_or_create
six.reraise(*exc_info)
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/db/models/query.py", line 380, in get_or_create
obj.save(force_insert=True, using=self.db)
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/db/transaction.py", line 305, in __exit__
connection.commit()
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/db/backends/__init__.py", line 168, in commit
self._commit()
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/db/backends/__init__.py", line 136, in _commit
return self.connection.commit()
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/carl/.virtualenvs/fecfc/lib/python2.7/site-packages/django/db/backends/__init__.py", line 136, in _commit
return self.connection.commit()
django.db.utils.OperationalError: cannot commit - no transaction is active
(running with django-nose gives weirder, inconsistent results)
Any clues on how to prevent this issue, which is currently standing in the way of CI?
I haven't used Ghost myself but for a similar test I had to use TransactionTestCase to get a similar test working. Could you try changing GhostTestCase and see if that's working?
Related
One of my python modules(which is not directly associated with Django application, same project though) is supposed to use Django models(that belong to original Django application) for convenient DB queries via Django-ORM.
However, this only works well until there is a DB or site-to-site connection issue.
Reproduced 100% times with following steps:
Create models.
Import models by setting up Django in any python module
os.environ['DJANGO_SETTINGS_MODULE'] = 'ServiceName.settings'
django.setup()
from ServiceName.models import ModelName
Use models via django ORM to fetch some data from DB on service startup(lets call it step 1) and later on by some triggers(lets call it step 2). In my case data is fetched once on startup, and all the subsequent times on certain Kafka event.
e.g.
query_results = ModelName.objects.filter(your_filter=some_value)
4.Shutdown PostgreSQL instance after step one, but before step 2
Not sure if related to the issue, but we are using pg-bouncer as a connection point.
5.Start PostgreSQL, trigger step2.
First attemp to fetch the data fails with the following trace:
Traceback (most recent call last):
File "/opt/services/_init_.py", line 113, in observe_events
if callback(event):
File "services_logparser_core.py", line 193, in process_event
r_handler.update_rules()
File "services_logparser_core.py", line 48, in update_rules
self.rules_list = self._fetch_enabled_rules()
File "services_logparser_core.py", line 69, in _fetch_enabled_rules
for sr in enabled_search_rules:
File "/usr/local/lib/python3.8/dist-packages/django/db/models/query.py", line 280, in _iter_
self._fetch_all()
File "/usr/local/lib/python3.8/dist-packages/django/db/models/query.py", line 1324, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/usr/local/lib/python3.8/dist-packages/django/db/models/query.py", line 51, in _iter_
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/usr/local/lib/python3.8/dist-packages/django/db/models/sql/compiler.py", line 1175, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.8/dist-packages/django/db/utils.py", line 90, in _exit_
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.OperationalError: SSL SYSCALL error: EOF detected
All the subsequent attempts to fetch the data fail with:
Traceback (most recent call last):
File "/opt/services/__init__.py", line 113, in observe_events
if callback(event):
File "services_logparser_core.py", line 193, in process_event
r_handler.update_rules()
File "services_logparser_core.py", line 48, in update_rules
self.rules_list = self._fetch_enabled_rules()
File "services_logparser_core.py", line 69, in _fetch_enabled_rules
for sr in enabled_search_rules:
File "/usr/local/lib/python3.8/dist-packages/django/db/models/query.py", line 280, in __iter__
self._fetch_all()
File "/usr/local/lib/python3.8/dist-packages/django/db/models/query.py", line 1324, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/usr/local/lib/python3.8/dist-packages/django/db/models/query.py", line 51, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/usr/local/lib/python3.8/dist-packages/django/db/models/sql/compiler.py", line 1173, in execute_sql
cursor = self.connection.cursor()
File "/usr/local/lib/python3.8/dist-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/django/db/backends/base/base.py", line 259, in cursor
return self._cursor()
File "/usr/local/lib/python3.8/dist-packages/django/db/backends/base/base.py", line 237, in _cursor
return self._prepare_cursor(self.create_cursor(name))
File "/usr/local/lib/python3.8/dist-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.8/dist-packages/django/db/backends/base/base.py", line 237, in _cursor
return self._prepare_cursor(self.create_cursor(name))
File "/usr/local/lib/python3.8/dist-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/django/db/backends/postgresql/base.py", line 236, in create_cursor
cursor = self.connection.cursor()
django.db.utils.InterfaceError: connection already closed
Application restart fixes the problem.
I don't set up a connection to the db manually anywhere(I only setup DB credentials), all the connections are handled by Django ORM.
Is there any django/psycopg setting can be configured inside the project so that new connection is established each time db query is required?
Django==3.2.6
from django import db
And
db.close_old_connections()
before
query_results = ModelName.objects.filter(your_filter=some_value)
Did the trick.
close_old_connections() method does not just close old connections, but also check if current connection is still usable. In case connection returns an error it will be closed. New connection opens automatically.
Nice to meet you.
Im from japan and If im not using properly English,please teach me.
Let me ask some questions.
I created a django project,and tried this code at the terminal.
python manage.py startapp myhp
Then models.py file has created.
Then I wrote some class and I tried this code at the terminal.
python manage.py startapp runserver
Then following error has occured.(I dont know which point is important,so Ill show all)
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\threading.py", line 926, in _bootstrap_inner
self.run()
File "C:\ProgramData\Anaconda3\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\management\commands\runserver.py", line 120, in inner_run
self.check_migrations()
File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\management\base.py", line 458, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\migrations\loader.py", line 49, in __init__
self.build_graph()
File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\migrations\loader.py", line 212, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\migrations\recorder.py", line 76, in applied_migrations
if self.has_table():
File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\migrations\recorder.py", line 56, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\base\introspection.py", line 48, in table_names
return get_names(cursor)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\base\introspection.py", line 43, in get_names
return sorted(ti.name for ti in self.get_table_list(cursor)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\sqlite3\introspection.py", line 73, in get_table_list
ORDER BY name""")
File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\sqlite3\base.py", line 394, in execute
return Database.Cursor.execute(self, query)
django.db.utils.DatabaseError: file is not a database
I tried to create the following file at the same directory(hp/myhhp/test.py),and it works well.
import sqlite3
dbname = 'TEST.db'
conn = sqlite3.connect(dbname)
cur = conn.cursor()
cur.execute('SELECT * FROM persons')
for row in cur:
print(row)
cur.close()
conn.close()
What is the point?
Im looking forward to your answer.
you have to say python manage.py runserver , not python python manage.py startapp runserver :) thats why u are getting error.
When I start tests I get error
~/work/some_project$ ./manage.py test
Raven is not configured (logging is disabled). Please see the documentation for more information.
/Users/ioganegambaputi/work/some_project/some_project/core/forms.py:7: RemovedInDjango19Warning: The django.forms.util module has been renamed. Use django.forms.utils instead.
from django.forms.util import ErrorList
/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/templated_email/__init__.py:2: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
from django.utils.importlib import import_module
/Users/ioganegambaputi/work/some_project/some_project/core/utils.py:50: RemovedInDjango19Warning: 'get_cache' is deprecated in favor of 'caches'.
self.cache = cache.get_cache(cache_alias or cache.DEFAULT_CACHE_ALIAS)
Creating test database for alias 'default'...
Got an error creating the test database: database "test_some_project" already exists
Type 'yes' if you would like to try deleting the test database 'test_some_project', or 'no' to cancel: yes
Destroying old test database 'default'...
/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/commands/loaddata.py:229: RemovedInDjango19Warning: initial_data fixtures are deprecated. Use data migrations instead.
RemovedInDjango19Warning
Traceback (most recent call last):
File "./manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/commands/test.py", line 90, in handle
failures = test_runner.run_tests(test_labels)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/test/runner.py", line 210, in run_tests
old_config = self.setup_databases()
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/test/runner.py", line 166, in setup_databases
**kwargs
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/test/runner.py", line 370, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 368, in create_test_db
test_flush=not keepdb,
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/__init__.py", line 120, in call_command
return command.execute(*args, **defaults)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 179, in handle
created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 365, in sync_apps
hide_empty=True,
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/__init__.py", line 120, in call_command
return command.execute(*args, **defaults)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/raven/contrib/django/management/__init__.py", line 37, in new_execute
return original_func(self, *args, **kwargs)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 60, in handle
self.loaddata(fixture_labels)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 90, in loaddata
self.load_label(fixture_label)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 147, in load_label
obj.save(using=self.using)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/serializers/base.py", line 173, in save
models.Model.save_base(self.object, using=using, raw=True)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/models/base.py", line 762, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/models/base.py", line 827, in _save_table
forced_update)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/models/base.py", line 877, in _do_update
return filtered._update(values) > 0
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/models/query.py", line 580, in _update
return query.get_compiler(self.db).execute_sql(CURSOR)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 1062, in execute_sql
cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 840, in execute_sql
cursor.execute(sql, params)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError
When I run my application on the localhost - all ok, it happens only with the test. This is my settings
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'some_project',
'USER': 'web',
'PASSWORD': '',
'HOST': ''
}
}
I use Django==1.8.4 and psql (PostgreSQL) 9.4.1.
I turned on database logs and nothing has been printed out on the console, but it works good when application normally running.
Also, I granted super user rights to the web user.
What is going wrong? How can I get more logs without debugging by hands?
This is on Microsoft SQL Server 2005.
Python 2.7.
Django 1.4
Django-MSSQL is installed and connecting to the database.
I can read tables, but not insert or update them. Working through django's tutorial on an empty database I get to this point:
# Save the object into the database. You have to call save() explicitly.
>>> p.save()
After save() is called I get this error message (which has also been reported):
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
UPDATE: I rolled back to Django 1.3 and this error went away. I suspect it is a change in how Django handles the users and authentication in 1.4. I'll take a look at source when I get a chance and try to patch.
Support for Django 1.4 was added with django-mssql v1.1
pip install django-mssql>=1.1
I have a new server just installed. Everything seems to be fine but when i run:
python manage.py syncdb
it generates follow error:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/usr/lib/python2.6/site-packages/django/core/management/commands/syncdb.py", line 109, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/usr/lib/python2.6/site-packages/django/core/management/sql.py", line 190, in emit_post_sync_signal
interactive=interactive, db=db)
File "/usr/lib/python2.6/site-packages/django/dispatch/dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
File "/usr/lib/python2.6/site-packages/django/contrib/auth/management/__init__.py", line 51, in create_permissions
content_type=ctype
File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", line 138, in create
return self.get_query_set().create(**kwargs)
File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 360, in create
obj.save(force_insert=True, using=self.db)
File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 460, in save
self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 553, in save_base
result = manager._insert(values, return_id=update_pk, using=using)
File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", line 195, in _insert
return insert_query(self.model, values, **kwargs)
File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 1436, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 791, in execute_sql
cursor = super(SQLInsertCompiler, self).execute_sql(None)
File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
cursor.execute(sql, params)
File "/usr/lib/python2.6/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/usr/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 86, in execute
return self.cursor.execute(query, args)
File "/usr/lib/python2.6/site-packages/MySQLdb/cursors.py", line 175, in execute
if not self._defer_warnings: self._warning_check()
File "/usr/lib/python2.6/site-packages/MySQLdb/cursors.py", line 89, in _warning_check
warn(w[-1], self.Warning, 3)
_mysql_exceptions.Warning: Incorrect string value: '\xE6\x99\xAF\xE9\xBB\x9E...' for column 'name' at row 1
All the tables and fields, in fact, created automatically without observable problem. I just wanna get rid of this error becoz the same thing does not happen in my old server with exactly the same project running on it.
So I am answering it here so that other people can have answer of same problem:
As said by Bill Kary:
He have solved this himself. Change all the collation of ALL tables AND fields to utf (utf8_general_ci) stops the error beautifully.