I have a Django app with a worker process which does database transactions. Under the hood, I have an Azure SQL database attached to my application. The worker code looks something like this:
class Command(BaseCommand):
def handle(self, *args, **kwargs):
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
django.setup()
consumer = Consumer()
logging.info('Booting drive consumer')
while True:
messages = consumer.poll()
for message in messages:
...
DriveEvent.objects.create(event_id=response['Id'], drive_id=drive_payload['drive_id'])
...
After about 20 mins, the create db object calls start failing with the following error:
[drive-consumer-1]2017-07-19T03:19:08.545128400Z Traceback (most recent call last):
[drive-consumer-1]2017-07-19T03:19:08.545133000Z File "/code/miles/management/commands/drive_consumer_worker.py", line 28, in handle
[drive-consumer-1]2017-07-19T03:19:08.545137900Z drive_consumer.consume(json.loads(record.value))
[drive-consumer-1]2017-07-19T03:19:08.545142500Z File "/code/miles/workers/drive_consumer.py", line 35, in consume
[drive-consumer-1]2017-07-19T03:19:08.545152200Z self._on_create(message['calendar_id'], drive_payload, message['access_token'])
[drive-consumer-1]2017-07-19T03:19:08.545156900Z File "/code/miles/workers/drive_consumer.py", line 46, in _on_create
[drive-consumer-1]2017-07-19T03:19:08.545161500Z DriveEvent.objects.create(event_id=response['Id'], drive_id=drive_payload['drive_id'])
[drive-consumer-1]2017-07-19T03:19:08.545166500Z File "/usr/local/lib/python2.7/site-packages/django/db/models/manager.py", line 85, in manager_method
[drive-consumer-1]2017-07-19T03:19:08.545171300Z return getattr(self.get_queryset(), name)(*args, **kwargs)
[drive-consumer-1]2017-07-19T03:19:08.545175900Z File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py", line 399, in create
[drive-consumer-1]2017-07-19T03:19:08.545180700Z obj.save(force_insert=True, using=self.db)
[drive-consumer-1]2017-07-19T03:19:08.545185400Z File "/usr/local/lib/python2.7/site-packages/django/db/models/base.py", line 796, in save
[drive-consumer-1]2017-07-19T03:19:08.545190200Z force_update=force_update, update_fields=update_fields)
[drive-consumer-1]2017-07-19T03:19:08.545194800Z File "/usr/local/lib/python2.7/site-packages/django/db/models/base.py", line 821, in save_base
[drive-consumer-1]2017-07-19T03:19:08.545211400Z with transaction.atomic(using=using, savepoint=False):
[drive-consumer-1]2017-07-19T03:19:08.545215800Z File "/usr/local/lib/python2.7/site-packages/django/db/transaction.py", line 184, in __enter__
[drive-consumer-1]2017-07-19T03:19:08.545220400Z connection.set_autocommit(False, force_begin_transaction_with_broken_autocommit=True)
[drive-consumer-1]2017-07-19T03:19:08.545224900Z File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 391, in set_autocommit
[drive-consumer-1]2017-07-19T03:19:08.545229600Z self._set_autocommit(autocommit)
[drive-consumer-1]2017-07-19T03:19:08.545234000Z File "/usr/local/lib/python2.7/site-packages/sql_server/pyodbc/base.py", line 453, in _set_autocommit
[drive-consumer-1]2017-07-19T03:19:08.545238600Z self.connection.autocommit = autocommit
[drive-consumer-1]2017-07-19T03:19:08.545243100Z File "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
[drive-consumer-1]2017-07-19T03:19:08.545247700Z six.reraise(dj_exc_type, dj_exc_value, traceback)
[drive-consumer-1]2017-07-19T03:19:08.545252200Z File "/usr/local/lib/python2.7/site-packages/sql_server/pyodbc/base.py", line 453, in _set_autocommit
[drive-consumer-1]2017-07-19T03:19:08.545256800Z self.connection.autocommit = autocommit
[drive-consumer-1]2017-07-19T03:19:08.545262600Z Error: ('08S01', '[08S01] [FreeTDS][SQL Server]Write to the server failed (20006) (SQLSetConnectAttr)')
Database init (in settings.py) looks something like this:
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': os.environ.get('DB_NAME'),
'HOST': os.environ.get('DB_HOST'),
'PORT': '1433',
'USER': os.environ.get('DB_USER'),
'PASSWORD': os.environ.get('DB_PASSWORD'),
'OPTIONS': {
'host_is_server': True,
'driver_supports_utf8': True,
'extra_params': 'tds_version=7.2;'
}
}
}
Per my experience, it seems to be caused by the tds_version that the 7.2 version does not support Azure SQL Database. Please refer to my answer for the other SO thread pymssql: Connection to the database only works sometimes to change to 7.3.
Possibly, the third-party project michiya/django-pyodbc-azure on GitHub may help for you to get the more details.
Hope it helps.
Related
i think below setting will work for the djongo to connect to the remote mongodb on mongodb.com but, the error message shows its still trying to connect to the localhost
DATABASES = {
'default': {
'ENGINE': 'djongo',
'HOST': 'mongodb+srv://<username>:<password>#cluster-name/<dbname>?retryWrites=true&w=majority',
}
below is the error traceback
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "venv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 120, in inner_run
self.check_migrations()
File "venv/lib/python3.6/site-packages/django/core/management/base.py", line 453, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "venv/lib/python3.6/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "venv/lib/python3.6/site-packages/django/db/migrations/loader.py", line 212, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "venv/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 73, in applied_migrations
if self.has_table():
File "venv/lib/python3.6/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 "venv/lib/python3.6/site-packages/django/db/backends/base/introspection.py", line 48, in table_names
return get_names(cursor)
File "venv/lib/python3.6/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 "venv/lib/python3.6/site-packages/djongo/introspection.py", line 47, in get_table_list
for c in cursor.db_conn.list_collection_names()
File "venv/lib/python3.6/site-packages/pymongo/database.py", line 856, in list_collection_names
for result in self.list_collections(session=session, **kwargs)]
File "venv/lib/python3.6/site-packages/pymongo/database.py", line 819, in list_collections
_cmd, read_pref, session)
File "venv/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1454, in _retryable_read
read_pref, session, address=address)
File "venv/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1253, in _select_server
server = topology.select_server(server_selector)
File "venv/lib/python3.6/site-packages/pymongo/topology.py", line 235, in select_server
address))
File "venv/lib/python3.6/site-packages/pymongo/topology.py", line 193, in select_servers
selector, server_timeout, address)
File "venv/lib/python3.6/site-packages/pymongo/topology.py", line 209, in _select_servers_loop
self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
I have met your problem before. In my case, I run django & mongodb inside containers. And I found that whatever setting I set inside setting.py, the djongo(they use pymongo behind) just ignore my setting.
For others seeking for the solution, you may want to check your syntax in setting.py which should look like below:
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'your-db-name',
'ENFORCE_SCHEMA': False,
'CLIENT': {
'host': 'host-name or ip address',
'port': port_number,
'username': 'db-username',
'password': 'password',
'authSource': 'db-name',
'authMechanism': 'SCRAM-SHA-1'
},
.......
}
Detail from djongo document
You can see the host, user, password fields are all under 'CLIENT' , which is different with the default syntax described by Django. So maybe most people get confused here and stuck at this problem.
Go to settings.py file and use below Database settngs
DATABASES = {
'default': {
'ENGINE': 'djongo',
'ENFORCE_SCHEMA': True
'NAME': 'your-db-name',
'HOST': 'host-name or ip address',
'PORT': port_number,
'USER': 'db-username',
'PASSWORD': 'password',
'AUTH_SOURCE': 'db-name',
'AUTH_MECHANISM': 'SCRAM-SHA-1',
}
Please also check out this article for connection between django and mongo db.
https://medium.com/#ksarthak4ever/how-to-use-django-with-mongodb-40ba36a21124
I personally recommend you please use pycharm. In Pycharm you can test your connection. So that you can get more clear image of whole scenario.
I use remote database in django. you can see in the below picture
I GOT THE SOLUTION
I adopted following approach >
so, behind the scene the djongo uses -> pymongo
and pymongo's default configuration are
class MongoClient(common.BaseObject):
HOST = "localhost" # here HOST has the hardcoded value
PORT = 27017
which lies in following file
venv/lib/python3.6/site-packages/pymongo/mongo_client.py
replace the harcoded value of HOST to something like
HOST = 'mongodb+srv://<username>:<password>#cluster-name/<dbname>?retryWrites=true&w=majority'
ADDITIONALLY
We can set the environment variable if we want
HOST = os.getenv('MONGO_DB_URL')
I am trying to migrate my Django model to the AWS Lightsail database, but I am getting below error. My database is on AWS Lightsail. it is PostgreSQL. I am deploying my project on AWS so I have set up almost everything except model migration.
AMAZON DATABASE AVAILABLE CONNECTION OPTIONS:
Endpoint-> ************.ap-******-1.***.amazonaws.com,
Port-> 5444,
User name-> db,
Password-> Something
MY SETTINGS.PY FILE DATABASE CONNECTION OPTIONS:
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': '****Endpoint*****',
'USER': 'db',
'PASSWORD': 'Something',
'HOST': '5444'
}
}
Terminal Error:
> `2, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/bitnami/portfolio/ManojJha-portfolio/.venv/lib/python3.7/site-packages/django/db/migrations/recorder.py", lin
e 76, in applied_migrations
if self.has_table():
File "/home/bitnami/portfolio/ManojJha-portfolio/.venv/lib/python3.7/site-packages/django/db/migrations/recorder.py", lin
e 56, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "/home/bitnami/portfolio/ManojJha-portfolio/.venv/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in
inner
return func(*args, **kwargs)
File "/home/bitnami/portfolio/ManojJha-portfolio/.venv/lib/python3.7/site-packages/django/db/backends/base/base.py", line
260, in cursor
return self._cursor()
File "/home/bitnami/portfolio/ManojJha-portfolio/.venv/lib/python3.7/site-packages/django/db/backends/base/base.py", line
236, in _cursor
self.ensure_connection()
File "/home/bitnami/portfolio/ManojJha-portfolio/.venv/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in
inner
return func(*args, **kwargs)
File "/home/bitnami/portfolio/ManojJha-portfolio/.venv/lib/python3.7/site-packages/django/db/backends/base/base.py", line
220, in ensure_connection
self.connect()
File "/home/bitnami/portfolio/ManojJha-portfolio/.venv/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in
inner
return func(*args, **kwargs)
File "/home/bitnami/portfolio/ManojJha-portfolio/.venv/lib/python3.7/site-packages/django/db/backends/base/base.py", line
196, in connect
conn_params = self.get_connection_params()
File "/home/bitnami/portfolio/ManojJha-portfolio/.venv/lib/python3.7/site-packages/django/db/backends/postgresql/base.py"
, line 165, in get_connection_params
self.ops.max_name_length(),
django.core.exceptions.ImproperlyConfigured: The database name '*****************Database End-point*****************.***.amazonaws.com' (85 characters) is longer than PostgreSQL's limit of 63 characters. Supply a shorter NAME in settings.DATABASES.```
So is there any way to shorten the endpoint name or there is any other solution to handle this error. Please guide me to set up this.
Thanks,
-Manoj Jha
"HOST" should be the hostname, not the port!
"NAME" is the name of the database.
An example from the Django documentation:
'ENGINE': 'django.db.backends.oracle',
'NAME': 'xe',
'USER': 'a_user',
'PASSWORD': 'a_password',
'HOST': 'dbprod01ned.mycompany.com',
'PORT': '1540',
Edit skip first part, I found out (well, they tell me) that the problem is in the database \edit
I Have a python+django project that I keep on two computers. I mean have two copy of the same project and sometimes I work on one, sometimes on the other. With copy-paste I lose the secret key in a settings.py (they were different but I overwrite). I don't know how generation and storage of secret keys works but to recover I start a new project, took the key and copied the files like this:
1) make a copy of the project
2) deleted the original project but kept the copy
3) started a new project with the same name (so, in the same folder like the original)
4) copied the new secret key
5) copied the files from the copy of the old project in the new project (so settings.py is lost and the new secret key with it, but I have a copy)
6) changed the secret key with the new secret key
But this don't works and it gives the same error like before:
System check identified no issues (0 silenced).
Unhandled exception in thread started by <function check_errors.<locals>.wrapper
at 0x0000000004ADAEA0>
Traceback (most recent call last):
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 216, in ensure_connection
self.connect()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\po
stgresql\base.py", line 174, in get_new_connection
connection = Database.connect(**conn_params)
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\psycopg2\__init__.py"
, line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATALE: autenticazione con password fallita per l'ut
ente "gm"
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\utils\autorelo
ad.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\core\managemen
t\commands\runserver.py", line 120, in inner_run
self.check_migrations()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\core\managemen
t\base.py", line 442, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\migrations\
executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\migrations\
loader.py", line 49, in __init__
self.build_graph()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\migrations\
loader.py", line 209, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\migrations\
recorder.py", line 61, in applied_migrations
if self.has_table():
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\migrations\
recorder.py", line 44, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_
names(self.connection.cursor())
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 255, in cursor
return self._cursor()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 232, in _cursor
self.ensure_connection()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 216, in ensure_connection
self.connect()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\utils.py",
line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 216, in ensure_connection
self.connect()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\po
stgresql\base.py", line 174, in get_new_connection
connection = Database.connect(**conn_params)
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\psycopg2\__init__.py"
, line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: FATALE: autenticazione con password fallita p
er l'utente "gm"
translated: authentication with password failed for user 'gm'
I'm not sure when it happened the first time but I have another problem, probabily linked: I can't access the database. Maybe this is the cause of the first problem and not the secret key.
I use PostgreSQL and I access it using the utility standard pgAdmin III. It gives me the initial screen with Servers: PostgreSQL 9.5, I right click on it and select connect, it ask me for password, I gives but it throws an error:
An error has occurred. Error connecting to the server: FATALE: autenticazione con password fallita per l'utente 'postgres'.
translated: authentication with password failed for user 'postgres'
I have created only one database and user so I have the standard postgres and my database 'possedimenti_db' with an user called 'gm'.
What can I do? I don't mind the data present, I can delete all but if it don't make me access I don't know how to delete.
Thank you
My settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'possedimenti_db',
'USER': 'gm',
'PASSWORD': database_key,
'HOST': host_key,
'PORT': '5432',
}
}
database_key and host_key are imported from external file.
Also database_key is different from the password I use to access the database with pgAdmin. In my other pc it works. I tried to change it in the other password but it throws anyway the same error.
Edit
You Can read the solution in the comments of the answer but the problem was that my user hadn't a password definited.
Use 'django.db.backends.postgresql_psycopg2' instead of 'django.db.backends.postgresql'.
you have to install psycopg2. Use this command:
pip install psycopg2
Here is the example:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'team_db',
'USER': 'jason',
'PASSWORD': 'abcd',
'HOST': 'localhost',
'PORT': '5432',
}
}
I'm currently trying to deploy a website built with the Python Flask framework to Webfaction. I've deployed a MongoDB to which I can succesfully connect from the MongoDB interactive interpreter:
[celli#web498 ~]$ mongo localhost:18209/admin
MongoDB shell version: 3.0.2
connecting to: localhost:18209/admin
> db.auth("awesomeusername", "anawesomepassword")
1
When starting the website, it can successfully connect using these credentials in my flask config.py file:
MONGODB_SETTINGS = {
'db': 'tc',
'port': 18209,
'username': 'awesomeusername',
'password': 'anawesomepassword',
}
But when I visit a page which does a query I get the error below. This code works perfectly well on another server, so the mistake lies somewhere in either the setup of my MongoDB instance, or in the connection to it. I also find it strange that setting up the connection works fine, but querying it creates this Authentication failed error.
Any idea how I can fix this? All tips are welcome!
File "/home/celli/webapps/tc/venv/lib/python2.7/site-packages/flask_login.py", line 758, in decorated_view
return func(*args, **kwargs)
File "/home/celli/webapps/tc/tc/app/views/webviews.py", line 220, in myTickets
userDocs = UserDocument.objects(id__in=[ticket.doc_id for ticket in userTickets])
File "/home/celli/webapps/tc/venv/lib/python2.7/site-packages/mongoengine/queryset/manager.py", line 37, in __get__
queryset = queryset_class(owner, owner._get_collection())
File "/home/celli/webapps/tc/venv/lib/python2.7/site-packages/mongoengine/document.py", line 168, in _get_collection
db = cls._get_db()
File "/home/celli/webapps/tc/venv/lib/python2.7/site-packages/mongoengine/document.py", line 162, in _get_db
return get_db(cls._meta.get("db_alias", DEFAULT_CONNECTION_NAME))
File "/home/celli/webapps/tc/venv/lib/python2.7/site-packages/mongoengine/connection.py", line 143, in get_db
source=conn_settings['authentication_source'])
File "/home/celli/webapps/tc/venv/lib/python2.7/site-packages/pymongo/database.py", line 978, in authenticate
self.connection._cache_credentials(self.name, credentials)
File "/home/celli/webapps/tc/venv/lib/python2.7/site-packages/pymongo/mongo_client.py", line 467, in _cache_credentials
auth.authenticate(credentials, sock_info, self.__simple_command)
File "/home/celli/webapps/tc/venv/lib/python2.7/site-packages/pymongo/auth.py", line 475, in authenticate
auth_func(credentials[1:], sock_info, cmd_func)
File "/home/celli/webapps/tc/venv/lib/python2.7/site-packages/pymongo/auth.py", line 450, in _authenticate_default
return _authenticate_scram_sha1(credentials, sock_info, cmd_func)
File "/home/celli/webapps/tc/venv/lib/python2.7/site-packages/pymongo/auth.py", line 238, in _authenticate_scram_sha1
sasl_start, sasl_continue)
File "/home/celli/webapps/tc/venv/lib/python2.7/site-packages/pymongo/auth.py", line 185, in _scram_sha1_conversation
res, _ = cmd_func(sock_info, source, sasl_start)
File "/home/celli/webapps/tc/venv/lib/python2.7/site-packages/pymongo/mongo_client.py", line 703, in __simple_command
helpers._check_command_response(response, None, msg)
File "/home/celli/webapps/tc/venv/lib/python2.7/site-packages/pymongo/helpers.py", line 182, in _check_command_response
raise OperationFailure(msg % errmsg, code, response)
OperationFailure: command SON([('saslStart', 1), ('mechanism', 'SCRAM-SHA-1'), ('autoAuthorize', 1), ('payload', Binary('n,,n=awesomeusername,r=NjAxNTEwMjc5MzAy', 0))]) on namespace tc.$cmd failed: Authentication failed.
MongoDB's users are per-database. In your example you show that you connect to the admin database, but the error message is simply telling you that your user is trying to authenticate with the tc database. Probably your user doesn't have a role on tc.
(The other possibility is that tc is not the database you want to connect to; you need to specify the correct database name in your connection params/string).
I'm trying to use django-mssql to connect to MS SQL Server 2008 R2 with Django 1.4.2 These are my Database settings:
DATABASE_ENGINE = 'sqlserver_ado'
DATABASE_NAME = 'dbtest'
DATABASE_USER = 'App'
DATABASE_PASSWORD = '*********'
DATABASE_HOST = 'localhost'
DATABASE_OPTIONS = {
'provider': 'SQLNCLI10',
'extra_params': 'DataTypeCompatibility=80;MARS Connection=True;',
}
DATABASES = {
'default': {
'ENGINE': DATABASE_ENGINE,
'NAME': DATABASE_NAME,
'USER': DATABASE_USER,
'PASSWORD': DATABASE_PASSWORD,
'HOST': DATABASE_HOST,
'OPTIONS' : DATABASE_OPTIONS,
},
}
This is the error I get when I try to syncdb
Traceback (most recent call last):
File "C:\Python27\DataSatellite\manage.py", line 11, in <module>
execute_manager(settings)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 459, in execute_manager
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 232, in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 371, in handle
return self.handle_noargs(**options)
File "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py", line 57, in handle_noargs
cursor = connection.cursor()
File "C:\Python27\lib\site-packages\django\db\backends\__init__.py", line 306, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "C:\Python27\lib\site-packages\sqlserver_ado\base.py", line 193, in _cursor
self.__connect()
File "C:\Python27\lib\site-packages\sqlserver_ado\base.py", line 168, in __connect
use_transactions=self.use_transactions,
File "C:\Python27\lib\site-packages\sqlserver_ado\dbapi.py", line 151, in connect
raise OperationalError(e, "Error opening connection: " + connection_string)
sqlserver_ado.dbapi.OperationalError: (AttributeError("'module' object has no attribute 'VARIANT'",), 'Error opening connection: DATA SOURCE=localhost;Initial Catalog=dbtest;UID=App;PWD=*********;PROVIDER=SQLNCLI10;MARS Connection=True;DataTypeCompatibility=80;MARS Connection=True;')
Finished "C:\Python27\DataSatellite\manage.py syncdb" execution.
I've looked everywhere and I cannot seem to understand and fix the problem. I hope someone can help!
Thanks!
Edit:
I've already created the database. I've also connected to the database using django-pyodbc, and I've successfully read and written from the database. But django-pyodbc causes problems when I use Apache, which was why I decided to try django-mssql. However, I do not understand the error it comes up with.
My Django (1.4.2) and Python (2.7) installs run on Windows, and I'm using an Apache webserver.
Update pywin32 to build 217 or greater. I found another question on stackoverflow with the same issue (on another topic):
Python COM server throws 'module' object has no attribute 'VARIANT'