title: DRF: AttributeError: 'str' object has no attribute 'pk'
body: <p>I am using Django Rest Framework. I have a model TestSuite which has Foreign key relations to the model Team and EmailTemplates. When I do a post() to Test Suite through postman, the data is inserted in the TestSuite table and request works successfully. However, when I do a get() or try to click on the url link from localhost to access TestSuite, it throws below error</p>
  
  <pre><code> AttributeError at /dqf_api/test_suite/
   'str' object has no attribute 'pk'
  </code></pre>
  
  <p>error traceback</p>
  
  <pre><code>File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py" in inner
  35.             response = get_response(request)
  
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py" in _get_response
  128.                 response = self.process_exception_by_middleware(e, request)
  
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py" in _get_response
  126.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
  
  File "/usr/lib/python3.6/contextlib.py" in inner
  52.                 return func(*args, **kwds)
  
  File "/usr/local/lib/python3.6/dist-packages/django/views/decorators/csrf.py" in wrapped_view
  54.         return view_func(*args, **kwargs)
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/viewsets.py" in view
  116.             return self.dispatch(request, *args, **kwargs)
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py" in dispatch
  495.             response = self.handle_exception(exc)
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py" in handle_exception
  455.             self.raise_uncaught_exception(exc)
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py" in dispatch
  492.             response = handler(request, *args, **kwargs)
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/mixins.py" in list
  48.         return Response(serializer.data)
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py" in data
  768.         ret = super(ListSerializer, self).data
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py" in data
  262.                 self._data = self.to_representation(self.instance)
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py" in to_representation
  686.             self.child.to_representation(item) for item in iterable
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py" in &lt;listcomp&gt;
  686.             self.child.to_representation(item) for item in iterable
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py" in to_representation
  530.                 ret[field.field_name] = field.to_representation(attribute)
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/relations.py" in to_representation
  272.         return value.pk
  
  Exception Type: AttributeError at /dqf_api/test_suites/
  Exception Value: 'str' object has no attribute 'pk'
  </code></pre>
  
  <p>models.py</p>
  
  <pre><code>class Team(models.Model):
      team_name = models.CharField(primary_key=True, max_length=30)
      description = models.CharField(max_length=100, blank=True, null=True)
  
      class Meta:
          managed = False
          db_table = 'team'
  
  class TestSuite(models.Model):
      team_name = models.ForeignKey(Team, on_delete=models.DO_NOTHING, db_column='team_name')
      suite_name = models.CharField(max_length=100)
      description = models.CharField(max_length=200, blank=True, null=True)
      schedule = models.CharField(max_length=100, blank=True, null=True)
      email_list_ok = models.CharField(max_length=200, blank=True, null=True)
  email_list_fail = models.CharField(max_length=200, blank=True, null=True)
  template_name = models.ForeignKey(EmailTemplates, on_delete=models.DO_NOTHING, db_column='template_name')
  
      class Meta:
          managed = False
          db_table = 'test_suite'
          unique_together = (('team_name', 'suite_name'),)
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>class TestSuiteViewSet(viewsets.ModelViewSet):
      queryset = models.TestSuite.objects.values('team_name','suite_name', 'description','schedule','email_list_ok','email_list_fail','template_name')
      serializer_class = serializers.TestSuiteSerializer
  
  class TeamViewSet(viewsets.ModelViewSet):
      queryset = models.Team.objects.all()
      serializer_class = serializers.TeamSerializer
  </code></pre>
  
  <p>serializers.py</p>
  
  <pre><code>class TestSuiteSerializer(serializers.ModelSerializer):
      class Meta:
          model = models.TestSuite
          fields = ['team_name','suite_name', 'description','schedule','email_list_ok','email_list_fail','template_name']
  </code></pre>
  
  <p>Can someone please help here. I am new to django and DRF</p>
  
  <p><strong>EDIT</strong>
  When I used queryset = models.TestSuite.objects.all() in serializers.py, it throws below error.</p>
  
  <pre><code>File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)
  
  File "/usr/local/lib/python3.6/dist-packages/django/db/backends/mysql/base.py" in execute
  71.             return self.cursor.execute(query, args)
  
  File "/usr/local/lib/python3.6/dist-packages/MySQLdb/cursors.py" in execute
  206.         res = self._query(query)
  
  File "/usr/local/lib/python3.6/dist-packages/MySQLdb/cursors.py" in _query
  312.         db.query(q)
  
  File "/usr/local/lib/python3.6/dist-packages/MySQLdb/connections.py" in query
  224.         _mysql.connection.query(self, query)
  
  The above exception ((1054, "Unknown column 'test_suite.id' in 'field list'")) was the direct cause of the following exception:
  
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py" in inner
  35.             response = get_response(request)
  
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py" in _get_response
  128.                 response = self.process_exception_by_middleware(e, request)
  
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py" in _get_response
  126.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
  
  File "/usr/lib/python3.6/contextlib.py" in inner
  52.                 return func(*args, **kwds)
  
  File "/usr/local/lib/python3.6/dist-packages/django/views/decorators/csrf.py" in wrapped_view
  54.         return view_func(*args, **kwargs)
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/viewsets.py" in view
  116.             return self.dispatch(request, *args, **kwargs)
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py" in dispatch
  495.             response = self.handle_exception(exc)
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py" in handle_exception
  455.             self.raise_uncaught_exception(exc)
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py" in dispatch
  492.             response = handler(request, *args, **kwargs)
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/mixins.py" in list
  48.         return Response(serializer.data)
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py" in data
  768.         ret = super(ListSerializer, self).data
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py" in data
  262.                 self._data = self.to_representation(self.instance)
  
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py" in to_representation
  686.             self.child.to_representation(item) for item in iterable
  
  File "/usr/local/lib/python3.6/dist-packages/django/db/models/query.py" in __iter__
  272.         self._fetch_all()
  
  File "/usr/local/lib/python3.6/dist-packages/django/db/models/query.py" in _fetch_all
  1179.             self._result_cache = list(self._iterable_class(self))
  
  File "/usr/local/lib/python3.6/dist-packages/django/db/models/query.py" in __iter__
  54.         results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  
  File "/usr/local/lib/python3.6/dist-packages/django/db/models/sql/compiler.py" in execute_sql
  1064.             cursor.execute(sql, params)
  
  File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py" in execute
  100.             return super().execute(sql, params)
  
  File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py" in execute
  68.         return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  
  File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py" in _execute_with_wrappers
  77.         return executor(sql, params, many, context)
  
  File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)
  
  File "/usr/local/lib/python3.6/dist-packages/django/db/utils.py" in __exit__
  89.                 raise dj_exc_value.with_traceback(traceback) from exc_value
  
  File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)
  
  File "/usr/local/lib/python3.6/dist-packages/django/db/backends/mysql/base.py" in execute
  71.             return self.cursor.execute(query, args)
  
  File "/usr/local/lib/python3.6/dist-packages/MySQLdb/cursors.py" in execute
  206.         res = self._query(query)
  
  File "/usr/local/lib/python3.6/dist-packages/MySQLdb/cursors.py" in _query
  312.         db.query(q)
  
  File "/usr/local/lib/python3.6/dist-packages/MySQLdb/connections.py" in query
  224.         _mysql.connection.query(self, query)
  
  Exception Type: OperationalError at /dqf_api/test_suites/
  Exception Value: (1054, "Unknown column 'test_suite.id' in 'field list'")
  </code></pre>