Guga Figueiredo
Guga Figueiredo

Reputation: 292

Django - Connecting to existing RDS postgres

I am trying to make a Django app to connect to an existing RDS postgres instance

I have changed my settings.py file to the following:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': <db-name>,
        'USER': <username>,
        'PASSWORD': <pswd>,
        'HOST': 'project-hash.us-east-1.rds.amazonaws.com',
        'PORT': '5432',
    }
}

After creating Django project, running python manage.py migrate yelds:

Tracking file by folder pattern:  migrations
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying auth.0001_initial...Traceback (most recent call last):
  File "/home/gustavo.figueiredo/anaconda3/envs/lp_admin/lib/python3.7/site-packages/django/db/backends/utils.py", line 82, in _execute
    return self.cursor.execute(sql)
psycopg2.errors.DuplicateTable: relation "auth_permission" already exists

Upvotes: 0

Views: 732

Answers (2)

jjanes
jjanes

Reputation: 44137

psycopg2.errors.DuplicateTable: relation "auth_permission" already exists

You do not have a problem connecting. To get this error, you must already be connected.

The problem is that the migration you are trying to run is incompatible with the database you are connected to.

Upvotes: 0

inim
inim

Reputation: 146

manage.py migrate will always fail if it tries to run a migration and finds that any action it's attempting to perform -- in this case, create a table to store user permission data -- has already been done.

If the database instance already exists, you would be much better served making use of manage.py inspectdb to create models from the database, rather than using manage.py migrate to apply models to the database.

If your database is an existing Django database, and you're looking to just get the migrations up and running, the simplest way is to run python manage.py migrate --fake-initial to mark the migration as having been applied without actually performing any database operations other than bumping the migration version.

Upvotes: 3

Related Questions