15

I'm trying to set up PostgresSQL for the first time on Django, running into this error when I try to do a syndb?

ImportError: Could not import settings 'testapp.settings' (Is it on sys.path?):

Also have this at the toop of my settings.py file, no idea if this is correct?

import dj_database_url
DATABASES = {'default': dj_database_url.config(default=os.environ.get('DATABASE_URL'))}
animuson
  • 53,861
  • 28
  • 137
  • 147
zhuyxn
  • 6,671
  • 9
  • 38
  • 44

2 Answers2

44

You don't give a lot of information about exactly where you are trying to run your sync db? Locally? Or up on Heroku? My answer is going to assume that it's locally.

Basically, you need to have virtualenv install and pip. While working in your virtualenv (with it activated), you need to do a

 pip install dj-database-url

Then you need to do a:

 pip freeze > requirements.txt

Getting up and going on Python+Django+Heroku is not a really hard thing to do... but, there are quite a few steps. If you are fuzzy, I recommend the Heroku Django tutorial.

David S
  • 12,967
  • 12
  • 55
  • 93
  • 3
    The Heroku Django tutorial assumes you know a lot as a developer. If all you ever have done is develop django projects locally it is a big leap and nowhere near documented enough to aid that transition (not that it is their job to have to do so) e.g. they never link to or explain the importance of gunicorn. To add to the confusion their [template project](https://github.com/heroku/heroku-django-template) does not use a virtual machine and the tutorial starts of with using one (which messes up the template project). I am sure it is easier for those more knowledgeable, but it is not to me :) – SumNeuron Sep 13 '17 at 12:08
  • Seriously speaking, my server was crashing and i didn't know i had forgotten to install the dependence, – kaybrian Jul 29 '23 at 23:22
2

You have to install dj-database-url.

Add it to your requirements.txt file.

Kenneth Reitz
  • 8,559
  • 4
  • 31
  • 34
  • I'm getting this error even though I'm not using a database. I removed all database dependencies (as far as I can tell anyway). Is this just the heroku way to require dj-database-url? Sure enough after installing dj-database-url my app works fine. – aaaaaa Jan 01 '15 at 01:26