0

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
6
  • Does "./manage.py migrate" work as expected with a local Postgres server ? I suspect it does not work too. Commented Dec 19, 2019 at 14:23
  • it did in a previous attempt. I created the postgres db locally and set it up, before trying to connect to the remote one Commented Dec 19, 2019 at 14:35
  • What's in the existing RDS instance? Does it already contain tables and data? And how do these relate to the django app you're trying to connect? Commented Dec 19, 2019 at 15:04
  • @dirkgroten I have a web2py application with a large database and I just wanted to use the same DB for a new django app Commented Dec 19, 2019 at 17:55
  • Then you should use create a new database in the same RDS. You can’t use the same database. (NAME should be different) Commented Dec 19, 2019 at 17:57

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

what if my database is not an existing Django database? in my case specifically, I have a web2py app currently working with this database
0

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.

1 Comment

this answered my original question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.