Search code examples
pythondjangopostgresqlcookiecutter-django

Project created using cookiecutter-django not running


Its been a few months that I am trying to learn Django. In the same process (and while reading "Two Scoops of Django 1.11"), I came across Cookiecutter Django. It has helped me learn a few important things to keep in mind while creating a project.

I tried to run the template provided by cookiecutter-django but failed. Here are the steps that I followed.

  1. Create a virtual environment named test and activate it.

mkvirtualenv test

  1. Installed Cookiecutter.

pip install coockiecutter

  1. Installed Cookiecutter Django, The project name was set to "Test Project" and other defaults settings were chosen. I am using PostgreSQL 9.6. cookiecutter https://github.com/pydanny/cookiecutter-django
  2. Create a database named "test_project" in PostgreSQL.
  3. Run python manage.py migrate

The result was the error:

django.db.utils.OperationalError: FATAL:  role "dev" does not exist

I have also tried making a user named test_project_user and granting it all the privileges to test_project database. I am still getting the same error.


Solution

  • The problem seems to be that you specified a database user that does not exist (or you left blank and it assumes your system user), in:

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql',
            'NAME': 'test_project',
            'USER': 'HERE', # Set test_project_user here
            ...
        }
    }