简体   繁体   中英

RHEL - Transitioned Django project from Windows throws django.db.utils.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found

I inherited a Django project from a former colleague. My first job is to migrate the development version from our production Windows server to a RHEL server. This Django app connect to a Microsoft SQL Server on the intranet.

I've setup the same versions of Python and Django that were on Windows, installed the same libraries, fixed the hard coded filesystem paths, and set up a virtual environment that's the same as the one in use on Windows.

When I run

python manage.py runserver

I get the error

Performing system checks...

System check identified no issues (0 silenced).
Unhandled exception in thread started by <function wrapper at 0x7eff42540de8>
Traceback (most recent call last):
  File "/srv/P27_D19/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/srv/P27_D19/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 124, in inner_run
    self.check_migrations()
  File "/srv/P27_D19/lib/python2.7/site-packages/django/core/management/base.py", line 437, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "/srv/P27_D19/lib/python2.7/site-packages/django/db/migrations/executor.py", line 20, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/srv/P27_D19/lib/python2.7/site-packages/django/db/migrations/loader.py", line 52, in __init__
    self.build_graph()
  File "/srv/P27_D19/lib/python2.7/site-packages/django/db/migrations/loader.py", line 203, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/srv/P27_D19/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
    self.ensure_schema()
  File "/srv/P27_D19/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 52, in ensure_schema
    if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
  File "/srv/P27_D19/lib/python2.7/site-packages/django/db/backends/base/base.py", line 231, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/srv/P27_D19/lib/python2.7/site-packages/django/db/backends/base/base.py", line 204, in _cursor
    self.ensure_connection()
  File "/srv/P27_D19/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
    self.connect()
  File "/srv/P27_D19/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/srv/P27_D19/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
    self.connect()
  File "/srv/P27_D19/lib/python2.7/site-packages/django/db/backends/base/base.py", line 171, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/srv/P27_D19/lib/python2.7/site-packages/sql_server/pyodbc/base.py", line 302, in get_new_connection
    timeout=timeout)
django.db.utils.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')

I've installed py-odbc , unixODBC , and unixODBC-devel . I pinged the database server by its hostname and it successfully finds that server. We have authentication setup such that it will automatically authenticate using Active Directory.

I noticed that sometimes this error message has been associated with freetds but freetds is not in use on the production version of this app, so I shouldn't need it (though I did try installing it and it didn't help anyway).

The last line of your quoted error is has the part that matters --

django.db.utils.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')

It's unsurprising that FreeTDS is not in use on the production version of this app, because most Windows users start (if not stay) with the built-in ODBC driver (and driver manager) from Microsoft.

Your Linux environment may not be fully set up, and it appears that you have not installed any ODBC driver for SQL Server, and certainly not configured any DSNs with such if you've installed one.

These are not present on Linux until/unless you install them, but one of each is required for your PyODBC app to function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM