0

I have been working on a Django app locally and it's now time to deploy it to a staging machine.

My Postgres database on the staging machine has a different username and password to my local machine.

I have got the Django app running okay on the remote machine, except that the database has not been initialised.

I assume that I should do this with migrate, so I try running:

$ python manage.py migrate

But I see the following error:

django.db.utils.OperationalError: FATAL:  no pg_hba.conf entry 
for host "127.0.0.1", user "mylocalusername", database "mylocaldbname"

It's failing because it doesn't allow me to log in with mylocalusername.

I assume that mylocalusername etc must be coming from the migrations files? Certainly the local username isn't set anywhere else on the staging machine, either in my settings file, or on the actual database itself.

How can I set up this database on the staging server?

I guess one way would be to delete everything in migrations and create a new local migration. Is that what I need to do?

I thought migrations were supposed to checked into source code, though, so I'd rather not delete all of them. Also, I want to carry on working on locally and updating my staging and production machines, so I need to find a sustainable way of doing this.

Richard
  • 62,943
  • 126
  • 334
  • 542
  • Figured it out: I needed to point `manage.py` explicitly at my staging settings file, like this: `python manage.py migrate --settings=myapp.settings.staging` – Richard Mar 03 '15 at 16:31

1 Answers1

0

"mylocalusername" comes from settings.py file.

It should looks like this:

   DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
            'NAME': 'mylocaldbname',                      # Or path to database file if using sqlite3.
            # The following settings are not used with sqlite3:
            'USER': 'mylocalusername',
            'PASSWORD': 'password',
            'HOST': 'localhost',                      # Empty for localhost through domain sockets or           '127.0.0.1' for localhost through TCP.
            'PORT': '',                      # Set to empty string for default.
        }
    } 

You can change it or create a valid user in your postgres database.

levi
  • 22,001
  • 7
  • 73
  • 74