I am trying to perform a sudo ./manage.py dumpdata on a mssql db from my django project, but keep getting:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/commands/dumpdata.py", line 158, in handle
stream=self.stdout)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/serializers/__init__.py", line 128, in serialize
s.serialize(queryset, **options)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/serializers/base.py", line 52, in serialize
for obj in queryset:
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/commands/dumpdata.py", line 150, in get_objects
for obj in queryset.iterator():
File "/opt/bitnami/python/lib/python2.7/site-packages/django/db/models/query.py", line 265, in iterator
for row in compiler.results_iter():
File "/opt/bitnami/python/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 701, in results_iter
for rows in self.execute_sql(MULTI):
File "/opt/bitnami/python/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 785, in execute_sql
cursor = self.connection.cursor()
File "/opt/bitnami/python/lib/python2.7/site-packages/django/db/backends/__init__.py", line 165, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/opt/bitnami/python/lib/python2.7/site-packages/sql_server/pyodbc/base.py", line 230, in _cursor
autocommit=autocommit)
pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')
I have done the configuration mentioned in https://code.google.com/p/django-pyodbc/wiki/FreeTDS, and I get all the test working (FreeTDS & ODBC).
Here is my current settings.py database config:
DATABASES = {
...
'vcoe':
{
'ENGINE' : 'sql_server.pyodbc',
'NAME' : 'VOIP',
'USER' : '******',
'PASSWORD' : '******',
'OPTIONS' : {
'driver': 'FreeTDS',
'dsn': 'VCOE',
}
}
}
DATABASE_ENGINE = 'sql_server.pyodbc'
DATABASE_NAME = 'VOIP'
DATABASE_USER = '******'
DATABASE_PASSWORD = '******'
DATABASE_OPTIONS = {
'driver': 'FreeTDS',
'dsn': 'VCOE', # ODBC DSN name defined in your odbc.ini
}
When I try and run ./manage.py test I get:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/commands/test.py", line 50, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/commands/test.py", line 71, in execute
super(Command, self).execute(*args, **options)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/commands/test.py", line 88, in handle
failures = test_runner.run_tests(test_labels)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/test/runner.py", line 147, in run_tests
old_config = self.setup_databases()
File "/opt/bitnami/python/lib/python2.7/site-packages/django/test/runner.py", line 109, in setup_databases
return setup_databases(self.verbosity, self.interactive, **kwargs)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/test/runner.py", line 299, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "/opt/bitnami/python/lib/python2.7/site-packages/django/db/backends/creation.py", line 362, in create_test_db
self._create_test_db(verbosity, autoclobber)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/db/backends/creation.py", line 455, in _create_test_db
with self._nodb_connection.cursor() as cursor:
File "/opt/bitnami/python/lib/python2.7/site-packages/django/db/backends/__init__.py", line 167, in cursor
cursor = utils.CursorWrapper(self._cursor(), self)
File "/opt/bitnami/python/lib/python2.7/site-packages/sql_server/pyodbc/base.py", line 181, in _cursor
raise ImproperlyConfigured('You need to specify NAME in your Django settings file.')
django.core.exceptions.ImproperlyConfigured: You need to specify NAME in your Django settings file.
I have tried to remove the DATABASES = {...} section and only leave the DATABASE_XXX but get:
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
Im currently using on client:
Ubuntu 14.04.1 LTS
Python 2.7.6
Django 1.7.8
pyodbc==3.0.10
django-pyodbc==0.2.8
Server I'm reaching is:
Microsoft Server 2003 running: MSSQL 2005
Here is /etc/odbcinst.ini:
[FreeTDS]
Description = TDS driver (Sybase/MS SQL)
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
CPTimeout =
CPReuse =
Double checked path, all files are present
Here is my /etc/odbc.ini:
[ODBC Data Sources]
ODBCNAME = Microsoft SQL Server
[VCOE]
Driver = FreeTDS
Description = VOIP Legacy Database
Trace = No
Servername = VOIP
Database = VOIP
[Default]
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
here is my /etc/freetds/freetds.conf:
[VOIP]
host = 142.117.139.***
port = 1433
tds version = 8.0
You're using a very, very old version of django-pyodbc that is no longer maintained. That was last updated in 2011. I've had problems with older versions and using dumpdata and dbshell. I would recommend using this version, actively maintained, which has been working wonderfully for me in several Django projects:
https://github.com/michiya/django-pyodbc-azure
Note, to install it, you'll have to do this, since you're not using Django 1.8:
pip install django-pyodbc-azure<1.8
Off-topic: I'd recommend using Django 1.8.x if you're just starting on a project. While Django 1.7.x is still supported, Django 1.8.x is a long-term release, meaning it will be supported for at least three years. Good luck!
Related
EDIT 1
have added _test.py with postgresql database connexion data but failed when I run I run the command py manage.py test cafe.tests.CafeTestCase --settings=core.settings._test
RuntimeWarning: Normally Django will use a connection to the 'postgres' database to avoid running initialization queries against the production database when it's not needed (for example, when running tests). Django was unable to create a connection to the 'postgres' database and will use the first PostgreSQL database instead.
warnings.warn(
Traceback (most recent call last):
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
self.connect()
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\base\base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\postgresql\base.py", line 178, in get_new_connection
connection = Database.connect(**conn_params)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\psycopg2\__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\core\management\commands\test.py", line 23, in run_from_argv
super().run_from_argv(argv)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\core\management\commands\test.py", line 53, in handle
failures = test_runner.run_tests(test_labels)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\test\runner.py", line 629, in run_tests
old_config = self.setup_databases(aliases=databases)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\test\runner.py", line 552, in setup_databases
return _setup_databases(
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\test\utils.py", line 170, in setup_databases
connection.creation.create_test_db(
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\base\creation.py", line 58, in create_test_db
self._create_test_db(verbosity, autoclobber, keepdb)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\base\creation.py", line 168, in _create_test_db
with self._nodb_connection.cursor() as cursor:
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\base\base.py", line 256, in cursor
return self._cursor()
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\base\base.py", line 233, in _cursor
self.ensure_connection()
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
self.connect()
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
self.connect()
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\base\base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\postgresql\base.py", line 178, in get_new_connection
connection = Database.connect(**conn_params)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\psycopg2\__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError
I have a Django app set with Docker and different developpement environment: dev, preprod, prod.
I use a postgresql database / pgaadmin 4 in my local Windows environment
I want to write and run tests 'outside' Docker in a VSCode terminal
(because if I use web container to run tests, changes in my tests.py are not updated so I need to down, build and re-run my containers)
so I run the command py manage.py test cafe.tests.CafeTestCase --settings=core.settings.preprod where I speficy the settings to consider
But I got an error sqlite3.OperationalError: no such function: Now because some data migrations use timezone.now() that i not available in sqlite
but I have specify test_database in my settings and given access to user so test should consider postgresql no?
_test.py
DATABASES = {
'default': {
"ENGINE": "django.db.backends.postgresql",
"NAME": "db_preprod",
"USER": "user_preprod",
"PASSWORD": "user_preprod",
"HOST": "localhost",
"PORT": "5433",
'TEST' : {
'NAME': 'test_db_preprod',
}
}
}
so you just have to create the database (or use an existing database) in your _test.py settings
Since SQLite does not provide the now() function, you need to to replace now() by datetime('now')
I'm working on a project using django-python. This has "oaisearch" installed to retrieve the metadata from different websites and "django_elasticsearch_dsl" to index them. It was verified that "oaisearch" runs without problems.
The problem occurs when "python3 manage.py search_index --create -f" is run to start indexing.
The file "documents.py" that has the configuration of what you want to index is the following.
from elasticsearch_dsl import analyzer
from django_elasticsearch_dsl import DocType, Index
from oaisearch.models import Digital_Resources
digital_resources = Index('digital_resources')
digital_resources.settings(
number_of_shards=1,
number_of_replicas=0
)
html_strip = analyzer(
'html_strip',
tokenizer="standard",
filter=["standard", "lowercase", "stop", "snowball"],
char_filter=["html_strip"]
)
#digital_resources.doc_type
class Resources(DocType):
class Meta:
model = Digital_Resources
fields = [
#'oai_server',
'creator',
'title',
'subject',
'description',
'identifier',
]
The console failure message after executing the aforementioned command is as follows
Creating index 'digital_resources'
PUT http://localhost:9200/digital_resources [status:400 request:0.014s]
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.5/dist-packages/django_elasticsearch_dsl/management/commands/search_index.py", line 128, in handle
self._create(models, options)
File "/usr/local/lib/python3.5/dist-packages/django_elasticsearch_dsl/management/commands/search_index.py", line 84, in _create
index.create()
File "/usr/local/lib/python3.5/dist-packages/elasticsearch_dsl/index.py", line 203, in create
self.connection.indices.create(index=self._name, body=self.to_dict(), **kwargs)
File "/usr/local/lib/python3.5/dist-packages/elasticsearch/client/utils.py", line 76, in _wrapped
return func(*args, params=params, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/elasticsearch/client/indices.py", line 88, in create
params=params, body=body)
File "/usr/local/lib/python3.5/dist-packages/elasticsearch/transport.py", line 318, in perform_request
status, headers_response, data = connection.perform_request(method, url, params, body, headers=headers, ignore=ignore, timeout=timeout)
File "/usr/local/lib/python3.5/dist-packages/elasticsearch/connection/http_urllib3.py", line 186, in perform_request
self._raise_error(response.status, raw_data)
File "/usr/local/lib/python3.5/dist-packages/elasticsearch/connection/base.py", line 125, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.RequestError: RequestError(400, 'mapper_parsing_exception', 'Root mapping definition has unsupported parameters: [doc : {properties={identifier={type=text}, creator={type=text}, subject={type=text}, description={type=text}, title={type=text}}}]')
What version of elasticsearch are you running? It looks like you are running elasticsearch 7.x which is not yet supported by your version of django_elasticsearch_dsl. Try looking for a newer version or using elasticsearch 6.x.
I have a Django project which has been developed with Python2.7, it is currently using Django version 1.10. I am now in the process of upgrading - first to Python3, and then afterwards I will do the Django upgrade.
When I make Python3 virtual environment and run the tests:
venv bash% ./manage.py tests
I get a massive traceback:
Traceback (most recent call last):
File "./manage.py", line 9, in <module>
execute_from_command_line( sys.argv )
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/commands/test.py", line 29, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/base.py", line 305, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/base.py", line 356, in execute
output = self.handle(*args, **options)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/commands/test.py", line 72, in handle
failures = test_runner.run_tests(test_labels)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/test/runner.py", line 549, in run_tests
old_config = self.setup_databases()
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/test/runner.py", line 499, in setup_databases
self.parallel, **kwargs
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/test/runner.py", line 743, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/backends/base/creation.py", line 70, in create_test_db
run_syncdb=True,
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 130, in call_command
return command.execute(*args, **defaults)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/base.py", line 356, in execute
output = self.handle(*args, **options)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 202, in handle
targets, plan, fake=fake, fake_initial=fake_initial
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/migrations/executor.py", line 97, in migrate
state = self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/migrations/executor.py", line 132, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/migrations/executor.py", line 237, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/migrations/operations/models.py", line 96, in database_forwards
schema_editor.create_model(model)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 271, in create_model
self.quote_name(field.column),
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 115, in quote_name
return self.connection.ops.quote_name(name)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/backends/sqlite3/operations.py", line 153, in quote_name
if name.startswith('"') and name.endswith('"'):
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
As I understand it the problem is unicode/string issues in the migrations? I have tried to follow the advice: "Add from __future__ import unicode_literals at the top every module". The resulting code still works nicely in Python2.7, but manage.py test fails in the same way for Python3.
For all it is worth the project seems to "basically" work in Python3 when I do:
bash% manage.py runserver
Update:
These are my database settings - might very well be something wrong with this, but observe that it has worked in Python2.7 for many years - and still does:
if "test" in sys.argv:
DATABASES = { 'default' : {
"ENGINE" : "django.db.backends.sqlite3",
"NAME" : "friskby.sqlite",
"TEST" : {
"NAME" : "friskby-test.sqlite"}}}
else:
DATABASE_URL = os.environ.get("DATABASE_URL")
if DATABASE_URL:
config = dj_database_url.config(default = DATABASE_URL)
DATABASES = { 'default': config }
else:
raise Exception("The DATABASE_URL environment variable has not bee set")
The comment from #Will Keeling set me on the right track. My migrations (originally created with Python2.7) had many:
... db_column = b"NAME_OF_COLUMN", ...
statements. I just removed all the leading b - and lo and behold all tests pass in both Python2.7 and Python3.
I am trying to run django's test suite for my application with two databases: one using postgres and the other using POSTGIS. Here is my DATABASES configuration:
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
...},
'POSTGIS': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
...}
When I run python manage.py test app I am prompted to delete an old test database, and when I say yes I get the following error:
Destroying old test database for alias 'default'...
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ubuntu/yes/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 "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/commands/test.py", line 90, in handle
failures = test_runner.run_tests(test_labels)
File "/home/ubuntu/yes/lib/python2.7/site-packages/django/test/runner.py", line 532, in run_tests
old_config = self.setup_databases()
File "/home/ubuntu/yes/lib/python2.7/site-packages/django/test/runner.py", line 482, in setup_databases
self.parallel, **kwargs
File "/home/ubuntu/yes/lib/python2.7/site-packages/django/test/runner.py", line 726, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "/home/ubuntu/yes/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 70, in create_test_db
run_syncdb=True,
File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/__init__.py", line 119, in call_command
return command.execute(*args, **defaults)
File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 172, in handle
self.sync_apps(connection, executor.loader.unmigrated_apps)
File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 285, in sync_apps
editor.create_model(model)
File "/home/ubuntu/yes/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 235, in create_model
definition, extra_params = self.column_sql(model, field)
File "/home/ubuntu/yes/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 134, in column_sql
db_params = field.db_parameters(connection=self.connection)
File "/home/ubuntu/yes/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 636, in db_parameters
type_string = self.db_type(connection)
File "/home/ubuntu/yes/lib/python2.7/site-packages/django/contrib/gis/db/models/fields.py", line 120, in db_type
return connection.ops.geo_db_type(self)
AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
Which version of Django are you using?
When you made the database changes, prior to anything else, did you use the appropriate command to update the databases and relationships to them, i.e., syncdb or migrate?
Answering those two questions will help diagnose the problem. Thanks!
UPDATE for close - I think I go through it and it was a bit of stupidity on my behalf.
python manage.py inspectdb > models.py
I was forgetting to pipe the output to a file!
I've dumped that into my app/models.py and now I'm just trying to get it running from there but going further.
I'm trying to get django running against an SQL Server 2008 R2 server.
I've figured out the FreeTDS/unixODBC connections. I can successfully do an isql and tsql query against the database.
I've been able to do a connection directly in python like so -
import pyodbc
cnxn = pyodbc.connect('DRIVER=FreeTDS;SERVER=servername;DATABASE=dbname;UID=user;PWD=pass;TDS_Version=8.0;')
cursor = cnxn.cursor()
result = cursor.execute("select name from tablea where name = 'hello'")
print result
If I do an inspectdb in django shell it's fine. It returns 70+ tables and their layout perfectly ok.
once I try to do a syndb it's spilling back the following error -
Creating tables ...
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 415, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/commands/syncdb.py", line 112, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/sql.py", line 216, in emit_post_sync_signal
interactive=interactive, db=db)
File "/usr/local/lib/python2.6/dist-packages/django/dispatch/dispatcher.py", line 185, in send
response = receiver(signal=self, sender=sender, **named)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/management/__init__.py", line 82, in create_permissions
ctype = ContentType.objects.db_manager(db).get_for_model(klass)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/contenttypes/models.py", line 47, in get_for_model
defaults = {'name': smart_text(opts.verbose_name_raw)},
File "/usr/local/lib/python2.6/dist-packages/django/db/models/manager.py", line 154, in get_or_create
return self.get_queryset().get_or_create(**kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 373, in get_or_create
return self.get(**lookup), False
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 301, in get
num = len(clone)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 77, in __len__
self._fetch_all()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 854, in _fetch_all
self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 220, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 710, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 771, in execute_sql
sql, params = self.as_sql()
File "/usr/local/lib/python2.6/dist-packages/sql_server/pyodbc/compiler.py", line 48, in as_sql
self._get_ordering(out_cols, supports_offset_clause or not do_offset)
File "/usr/local/lib/python2.6/dist-packages/sql_server/pyodbc/compiler.py", line 154, in _get_ordering
ordering, ordering_group_by = self.get_ordering()
ValueError: too many values to unpack
similarily if I try to do a query in django like so -
from myapp.models import tablea
tablea.objects.filter(id=5)
It fails with the following error message -
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 71, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 96, in __iter__
self._fetch_all()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 854, in _fetch_all
self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 220, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 710, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 771, in execute_sql
sql, params = self.as_sql()
File "/usr/local/lib/python2.6/dist-packages/sql_server/pyodbc/compiler.py", line 48, in as_sql
self._get_ordering(out_cols, supports_offset_clause or not do_offset)
File "/usr/local/lib/python2.6/dist-packages/sql_server/pyodbc/compiler.py", line 154, in _get_ordering
ordering, ordering_group_by = self.get_ordering()
ValueError: too many values to unpack
I'm not convinced these errors are related to the other thread found here -
ValueError: Too many values to unpack Django
But I'm no expert so I could be wrong. I know I did try to change my password and it won't let me connect similar error message -
>>> u = User.objects.get(username="user")
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/django/db/models/manager.py", line 151, in get
return self.get_queryset().get(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 301, in get
num = len(clone)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 77, in __len__
self._fetch_all()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 854, in _fetch_all
self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 220, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 710, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 771, in execute_sql
sql, params = self.as_sql()
File "/usr/local/lib/python2.6/dist-packages/sql_server/pyodbc/compiler.py", line 48, in as_sql
self._get_ordering(out_cols, supports_offset_clause or not do_offset)
File "/usr/local/lib/python2.6/dist-packages/sql_server/pyodbc/compiler.py", line 154, in _get_ordering
ordering, ordering_group_by = self.get_ordering()
ValueError: too many values to unpack
edit to add - when doing a query my model definition is as follows -
from django.db import models
# Create your models here.
class tablea(models.Model):
tablea_id = models.IntegerField()
tablea_name = models.CharField(max_length=32)
tablea_duration = models.IntegerField()
class Meta:
db_table = u'tablea'
def __unicode__(self):
return self.tablea_name, tablea_duration
edit to add that I've done a complete fresh reinstall. Wiped the VM and brought it back to life. Here's a breakdown of the steps done
apt-get install gcc g++ make python-dev
download unixODBC
tar xzvf unixODBC-2.3.2.tar.gz
./configure
make
makeinstall
download FreeTDS
tar xzvf freetds-stable.tgz
./configure --with-tdsver=8.0 --with-unixodbc=usr/local
make
make install
ldconfig -v
odbc.ini
[mssql]
Description = MSSQL Server
Driver = freetds
Database = database
Server = server
Port = 1433
TDS_Version = 8.0
odbcinst.ini
[freetds]
Description = MS SQL database access with Free TDS
Driver = /usr/local/lib/libtdsodbc.so
Setup = /usr/local/lib/libtdsS.so
UsageCount = 1
freetds.conf
[mssql]
host = server
port = 1433
tds version = 8.0
tsql -S mssql -U user -P password works
isql -v mssql user password works (for some reason simple isql -v mssql does not)
apt-get install python-setuptools
easy_install pip
pip install pyodbc
pip install Django==1.6
pip install django-pyodbc-azure
settings.py
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'HOST': "server\instance",
'USER': "username",
'PASSWORD': "password",
'NAME': "database",
'OPTIONS': {
'host_is_server': True,
'driver': 'FreeTDS',
'dsn': 'MSSQL',
},
}
}
It's a version incompatibility issue.
Django 1.6 changed the kind of value returned by django.db.models.sql.compiler.SQLCompiler.get_ordering. It returns a 3-element tuple, but pyodbc unpacks just two elements.
If you look at Django 1.5 version you see that it used to return a 2-element tuple as pyodbc expects.