Wednesday, May 31, 2017

Re: django.db.utils.OperationalError: server closed the connection unexpectedly

Hello,

DATABASES_DEFAULT = {

        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'litdb',
        'USER': 'root',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '80',
}

First, if this means what I think it means, it's a very nasty way to define your database. Instead, do this:

DATABASES = {      'default': {          'ENGINE': ...,          ...,      }  }

Now, for what you are asking, PostgreSQL does not listen on port 80; more likely it's listening on port 5432.

Regards,

A.

Antonis Christofides  http://djangodeployment.com
On 2017-05-31 14:35, Bobby Paul wrote:
Dear All,

I am getting this error message while trying to install psql database.

 File "setup.py", line 18, in <module>
    execute_from_command_line(['manage.py','migrate'])
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 93, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/executor.py", line 19, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/loader.py", line 47, in __init__
    self.build_graph()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/loader.py", line 191, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
    self.ensure_schema()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
    if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 162, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 135, in _cursor
    self.ensure_connection()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
    self.connect()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/utils.py", line 98, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
    self.connect()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 119, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 176, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/usr/local/bin/lib/python2.7/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
==========
DATABASES_DEFAULT = {

        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'litdb',
        'USER': 'root',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '80',
}

How to sort this issue?

Kind Regards
Bobby Paul
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b07acc86-a2a9-4fe7-9004-0f7a90fe4100%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

3 comments: