Search code examples
pythondjangoeclipsesqlitepydev

No such table error when running a django server from Eclipse


I'm developing a website using Django. When I run the server through the command prompt like so:

python manage.py runserver

it runs fine, but when I do it from Eclipse (right click on the project -> Run As... -> django project, I get the following error:

DatabaseError at /
no such table: django_session
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.3
Exception Type: DatabaseError
Exception Value:
no such table: django_session

Any ideas as to what can cause that? I'm not that proficient in django so I have no clue what file could be causing this - if you need me to post something, please ask here in the comments.


Solution

  • Probably Eclipse/PyDev is not able to find the database. Assuming that you use a sqlite3 database, use a full path in the DATABASES settings. Test it via the console and afterwards within Eclipse. That should work ;-)

    edit: As photioionized suggested, the best approach is to put those lines in settings.py

    import os
    PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
    

    and then to

    SQLITE_3 = os.path.join(PROJECT_PATH, 'YOUR DATABASE.DB')
    

    SQLITE_3 is now the full path to your sqlite3 database, whereever your django project lives.