1

Earlier i had a problem with my pyodbc module, that did not run my application on the apache server, running on my windows machine. I found to solve my problem of getting the django project to run on apache using this hint.

But now I am facing a bit of a different problem. The django application runs on apache but throws this error on the page.

ImproperlyConfigured at /auth/login/
settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

Just to be clear, this project runs perfectly when deployed through djangos inbuilt server. This is how my database connection looks like in the settings.py

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'myDbName',
        'USER': 'myusername',    
        'PASSWORD': '',
        'HOST': '',
        'OPTIONS' : {
            'driver': 'SQL Native Client',
            'dsn': 'test',
            'MARS_Connection': True,
        },
    },    
}

UPDATE:

I updated my code according to Django MSSQL Documentation, ran into a few problems and got it to work by updating my pywin32 And again this works on djangos inbuilt server and NOT APACHE giving me the same ImproperlyConfigured error

DATABASES = {
    'default': {
        'NAME': 'myDbName',
        'ENGINE': 'sqlserver_ado',
        'HOST': 'MYHOST',
        'USER': 'myusername',
        'PASSWORD': 'mypassword',
        'OPTIONS' : {
            'provider': 'SQLNCLI11', 
            'use_mars': False,
        },
    }
}

My system - Windows 7, Apache 2.2, python 2.7, django 1.4.2, pyodbc-3.0.6.win32-py2.7

Any hints or tips towards this is highly appriciated, i ahve been trying to get this project up and running for quite some time now.

Thanks alot

Community
  • 1
  • 1
shabeer90
  • 5,161
  • 4
  • 47
  • 65
  • Is Apache running on the same machine with access to the same Python packages? – Michael Mior Dec 10 '12 at 13:30
  • Yes, previously I have created demo django apps, that say "It worked! Congratulations on your first Django-powered page." and they ran perfectly using Apache. – shabeer90 Dec 10 '12 at 13:54
  • Were you using a different database engine in those cases? – Michael Mior Dec 10 '12 at 14:13
  • In one of them I used the "sqlite3" and the other I used the "sql_server.pyodbc". But now I am starting to have a funny feelings if its got something to do with versions, cuz this project was initially built on django 1.3 and I moved it to 1.4, changing the structure and everything, works fine on djangos inbuilt server, Wonder if something else that's missing in the settings.py – shabeer90 Dec 10 '12 at 14:27
  • I manage to get it work, it was to do with my DSN configuration. Had to give the database username and password while creating it, kinda funny i idid not have that problem while running it on djangos inbuilt server – shabeer90 Dec 10 '12 at 16:19
  • 1
    It would be great if you could post that as an answer to your own question and accept it so others can see how you solved your problem :) – Michael Mior Dec 10 '12 at 19:31

2 Answers2

1

If you are using a built-in backend, you should specify database engine as given below:

'ENGINE':'django.db.backends.mysql'

If you are not using a built-in backend you should specify a fully-qualified path (i.e. mypackage.backends.whatever) in the ENGINE setting. Information on defining database backend in given in django documentation here.

Update:
You can try using django-mssql for using sql-server with django and the clear documentation is available here in readthedocs.

arulmr
  • 8,620
  • 9
  • 54
  • 69
  • I am using a "sql-server" backend not mysql. Using 'ENGINE': 'sql_server.pyodbc', works when i run the project with djangos' inbuilt server. – shabeer90 Dec 10 '12 at 09:32
  • @shabeer90 If you are not using a built-in backend, you should specify the exact location of the package which is to be used. – arulmr Dec 10 '12 at 09:41
  • I'm not pretty much sure about it. You can try [this question](http://stackoverflow.com/q/842831/1095090). – arulmr Dec 10 '12 at 09:48
  • Tried using the link you sent me. Works fine while using djangos inbuilt server, BUT DOES NOT RUN ON APACHE :| – shabeer90 Dec 10 '12 at 11:17
0

The answer to my question might be a bit wierdbut hey this is how i got things to work on my machine.

The main problem I had was that my DSN was not getting connected with the django project, in the steps I have mentioned below, its the last step that made the whole difference in making it work. Previously I had selected "With integrated Windows authentication" while creating my DSN, but surprisingly it worked when I was running it using djangos inbuilt server.

  • Open the app ODBC Data Source Administrator in Windows 7 (search ODBC from Start Menu).
  • Under System DSN tab, click the Add button.
  • Select SQL Server Native Client 10.0
  • Enter DSN your_dsn_name, description(optional), and the SQL Server to connect , click Next
  • Select option “With SQL Server authentication using a login ID and password entered by the user”.
  • Enter Login ID ('your_username’) and password ('your_password’). Click Next, Next and Finish.

And i changed my database connection back to the original code

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'MaDaMa_App',
        'USER': 'your_username',
        'PASSWORD': 'your_password',
        'HOST': 'MYHOST',
        'OPTIONS' : {
            'driver': 'SQL Native Client',
            'dsn': 'your_dsn_name',
            'MARS_Connection': True,
        },
    },
 }

Thanks to all who helped me solve this, and hope this is helpfull for someone out there.

Cheers

shabeer90
  • 5,161
  • 4
  • 47
  • 65