title: Ruby: SQLite3::BusyException: database is locked:
body: <p>Ran into this error message whilst developing tonight: <code>SQLite3::BusyException: database is locked:</code></p>
  
  <p>I have two models: </p>
  
  <ul>
  <li>Podcasts have many Tracks </li>
  <li>Tracks belong to Podcasts.</li>
  <li>Podcast files are hosted on <a href="http://www.mixcloud.com">mixcloud</a>.</li>
  </ul>
  
  <p>To create a Podcast:</p>
  
  <ul>
  <li>user submits a url for a podcast on mixcloud</li>
  <li>rails app grabs json feed associated with url</li>
  <li>json is used to set attributes (title, image etc) on the new Podcast object</li>
  </ul>
  
  <p>I'm trying to get my rails app to take advantage of the fact that the json feed also details the names (and artists) of the Tracks that belong to this Podcast.</p>
  
  <p>I thought the following before_validation method would automatically create all associated Tracks whenever we create a new Podcast.</p>
  
  <pre><code>class Podcast &lt; ActiveRecord::Base
    attr_accessible :mixcloud_url, :lots, :of, :other, :attrs
    has_many :tracks    
    before_validation :create_tracks
    def create_tracks
      json = Hashie::Mash.new HTTParty.get(self.json_url)    
      json.sections.each do |section|
        if section.section_type=="track"
            Track.create(:name=&gt;section.track.name, :podcast_id=&gt;self.id)
        end
      end             
    end
  end
  </code></pre>
  
  <p>How can I get round this? It looks like rails (or sqlite3) doesn't like me creating new instances of an associated model in this way. How else can I do this? I suspect this is as much a rails problem as an sqlite3 one. I can post more code if it's gonna help.</p>