title: Unable to store a python class object in postgres database
body: <p>I have a class defined like below</p>
  
  <pre><code>class StatementStatus:
      def __init__(self, id, statement, call, intent, score):
          self.id = callback_id
          self.statement = statement
          self.entities = entities
          self.intent = intent
          self.score = score
  
      def getIntent(self):
          return self.intent
  
      def getScore(self):
          return self.score
  
      def addIntent(self, intent_val):
          self.intent.append(intent_val)
  </code></pre>
  
  <p>Now I want to store an instance of this class into postgres database.This file is hosted in a django server and I am unable to use django migrations due to some issues in the server.So I need to do it manually.</p>
  
  <p>Below is my django model</p>
  
  <pre><code>class StoreState(models.Model):
      context_name = models.CharField(null=True,max_length=100)
      state = models.BinaryField(null=True)
  </code></pre>
  
  <p>Here I want to store the StatementStatus instance in a field called state.</p>
  
  <p>Similarly my postgres table structure looks like below</p>
  
  <pre><code>    Column    |          Type          | Modifiers 
  --------------+------------------------+-----------
   id           | integer                | 
   context_name | character varying(100) | 
   state        | bytea                  | 
  </code></pre>
  
  <p>But it doesn't store any entry into the table when I do an operation like below</p>
  
  <pre><code>try:
      conv = StoreState.objects.create(
      context_name = callback_id,
      state=s
      )
  except Exception as e:
      print("unable to save update", e)
  </code></pre>
  
  <p>But it doesn't store anything into the table.I get the below error.</p>
  
  <pre><code>('unable to save update', TypeError("can't escape instance to binary",))
  </code></pre>
  
  <p>What am I doing wrong?</p>