title: Foreign key relationship with peewee and python
body: <p>I'm trying to set up a database ORM with peewee and am not clear on the use of foreign key relationships.</p>
  
  <pre><code>from peewee import *
  
  db = SqliteDatabase('datab.db')
  
  class datab(Model):
      class Meta:
          database = db
  
  class Collection(datab):
      identifier = CharField()
      title = CharField()
  
  class File(datab):
      identifier = ForeignKeyField(Collection, related_name='files')
      name = CharField()
  </code></pre>
  
  <p>Later, I do an import of "Collections"</p>
  
  <pre><code>for value in collection:
  Collection(**value).save()
  </code></pre>
  
  <p>Finally, where I am having trouble is adding the Files to the collections</p>
  
  <pre><code>for value in collectionFiles:
      File(**value).save()
  </code></pre>
  
  <p>Within the value dict, there is a keyword pair with key of "identifier" and a value that should associate with the Collection identifier keyword.</p>
  
  <p>However I get an error message:</p>
  
  <pre><code>ValueError: invalid literal for int() with base 10: 'somevalue'
  </code></pre>
  
  <p>If I change the File(datab): identifier Type to VarChar, it saves the data. </p>
  
  <p>I'm realizing I'm doing it wrong.  My assumption was that the unique identifier value in each table would apply the foreign key.  After reading the documentation, it looks like the foreign key setup is a bit different.  Do I need to do something like</p>
  
  <p>Collections.File.files(**values).save() ?  In other words, instead of doing a data import, loading the collection object and then adding the file associated fields through peewee?</p>
  
  <p>Values that make up class File</p>
  
  <pre><code>{'crc32': '63bee49d',
   'format': 'Metadata',
   'identifier': u'somevalue',
   'md5': '34104ffce9e4084fd3641d0decad910a',
   'mtime': '1368328224',
   'name': 'lupi.jpg_meta.txt',
   'sha1': '1448ed1159a5d770da76067dd1c53e94d5a01535',
   'size': '1244'}
  </code></pre>