1

I have a PostgreSQL database server which is read only transaction. I need to extract some from this database in Django. My setting.py file is given below:

{
  {
    DATABASES = {
      'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'supercaller',
        'USER' : 'chandra_m',
        'PASSWORD' : 'XXXXX',
        'HOST': 'xx.xxx.xxx.xxx',
        'PORT': '5432',
      }
    }
  }
}

I am running the server with python manage.py runserver. I am getting following error

  System check identified no issues (0 silenced).
  Unhandled exception in thread started by <function wrapper at 0x1aa9230>
  Traceback (most recent call last):
   File "/home/birendra/knowlarity/chandra/NodetoDjango/venv/local/lib/python2.7/site-   
   packages/django/utils/autoreload.py", line 222, in wrapper
   fn(*args, **kwargs)
  File "/home/birendra/knowlarity/chandra/NodetoDjango/venv/local/lib/python2.7/site - 
  packages/django/core/management/commands/runserver.py", line 107, in inner_run
    self.check_migrations()
  File "/home/birendra/knowlarity/chandra/NodetoDjango/venv/local/lib/python2.7/site-
  packages/django/core/management/commands/runserver.py", line 159, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "/home/birendra/knowlarity/chandra/NodetoDjango/venv/local/lib/python2.7/site-
  packages/django/db/migrations/executor.py", line 17, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/home/birendra/knowlarity/chandra/NodetoDjango/venv/local/lib/python2.7/site-
  packages/django/db/migrations/loader.py", line 48, in __init__
    self.build_graph()
  File "/home/birendra/knowlarity/chandra/NodetoDjango/venv/local/lib/python2.7/site-
  packages/django/db/migrations/loader.py", line 179, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/home/birendra/knowlarity/chandra/NodetoDjango/venv/local/lib/python2.7/site-
  packages/django/db/migrations/recorder.py", line 59, in applied_migrations
    self.ensure_schema()
  File "/home/birendra/knowlarity/chandra/NodetoDjango/venv/local/lib/python2.7/site-
  packages/django/db/migrations/recorder.py", line 53, in ensure_schema
    editor.create_model(self.Migration)
  File "/home/birendra/knowlarity/chandra/NodetoDjango/venv/local/lib/python2.7/site-
  packages/django/db/backends/schema.py", line 270, in create_model
    self.execute(sql, params)
  File "/home/birendra/knowlarity/chandra/NodetoDjango/venv/local/lib/python2.7/site-
  packages/django/db/backends/schema.py", line 98, in execute
    cursor.execute(sql, params)
  File "/home/birendra/knowlarity/chandra/NodetoDjango/venv/local/lib/python2.7/site- 
  packages/django/db/backends/utils.py", line 81, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/birendra/knowlarity/chandra/NodetoDjango/venv/local/lib/python2.7/site-
  packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/home/birendra/knowlarity/chandra/NodetoDjango/venv/local/lib/python2.7/site- 
  packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/birendra/knowlarity/chandra/NodetoDjango/venv/local/lib/python2.7/site-
  packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  django.db.utils.InternalError: cannot execute CREATE TABLE in a read-only transaction

However, I am able to access this database server through a shell prompt with

psql -h 46.xxx.xxx.52 supercaller chandra_m

How to fix the errors?

2
  • If you had a closer look to your exception stack trace, you could've noticed that a migration want to run a CREATE TABLE statement, which cannot be executed in a a read-only transaction -- so the connection itself is fine. Commented Jan 5, 2015 at 11:13
  • So what is the propable step should I take if I need to extract data from database server?? Commented Jan 5, 2015 at 11:33

2 Answers 2

2

you need to make sure your sessions are not using databases (default). I would consider leaving the 'default' to a writeable databaes, then add a 'readonly' database connection as an alternative connection for the objects that you are accessing in it.

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

Comments

0

First your log says, you have migrations that's not applied to the db you are connecting to, so fix it first.

Then I had success with the following in settings.py SESSION_ENGINE="django.contrib.sessions.backends.cache"

Comments

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.