Django: “Error importing authentication backend”

This is probably a very rare error that one may encounter in Django. But I think I should share it here, as it would save about an hour of anybody else who has this problem.

Problem
Exception Type: ImproperlyConfigured at /
Error importing authentication backend

Probable Cause
I was very desparate to change the name of an app inside my Django project. I renamed the folder name and all possible mentions of the application name anywhere in the code and the database tables (Please note: This is not recommended, there is probably a better solution to do this). Once I faced that problem with no clear indication of where I was going wrong, I looked everywhere in the code and the database. After going into panic mode, I tried desperately changing and removing anything that may break. In the end, I ran out of places to find the application name but the error still existed.

Solution
I had noticed after looking at my cookies that I still had cookies from my session, which meant that everytime I connected to the server, I was trying to pass my “delicious” cookies. But just deleting your own cookies won’t do it. The session object of the user was cached in the database inside the table “django_session”. This especially stores the “AUTHENTICATION_BACKENDS” last used. So, truncate the table: TRUNCATE TABLE django_session to finally get rid of this nasty problem.

11 thoughts on “Django: “Error importing authentication backend””

  1. Thank you for posting this, saved me so much time. This is a really nasty thing to track down.

Leave a Reply

Your email address will not be published. Required fields are marked *