title: How to access PostgreSQL database in Django application
body: <p>I have created a simple <code>Django</code> application which tries to access table named <code>fruits</code> present in <code>PostgreSQL</code> database and display its contents. I followed the official <code>Django</code> documentation and implemented below code as far as I understand. But below procedure is incomplete I believe as <code>fruits.objects.all()</code> is failing to fetch any data. I am missing something can anybody point it out any help would be appreciated.</p>
  
  <p><strong>Table: fruits</strong></p>
  
  <p><a href="https://i.stack.imgur.com/PEybS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PEybS.png" alt="enter image description here"></a></p>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>from django.db import models
  
  class fruits(models.Model):
      ID = models.CharField(max_length=20)
      Name = models.CharField(max_length=20)
  
      def __str__(self):
          return self.Name
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>from database.models import fruits
  
  def index(request):
      data = fruits.objects.all()
  
      print(len(data))
  
      for item in data:
          print(item)
  </code></pre>
  
  <p><strong>settings.py</strong></p>
  
  <pre><code>DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.postgresql_psycopg2',
          'NAME': '&lt;database_name&gt;',
          'USER': '&lt;user_name&gt;',
          'PASSWORD': '&lt;password&gt;',
          'HOST': '&lt;host_name&gt;',
          'PORT': '',
      }
  }
  </code></pre>