title: How to enforce referential integrity on the one side of a many-to-one relationship?
body: <p>Those are my models:</p>
  
  <pre><code>class Hero(models.Model):
      name = models.CharField(max_length=24)
  
  class Photo(models.Model):
      hero = models.ForeignKey(Hero)
      image = models.ImageField(upload_to='heroes')
  </code></pre>
  
  <p>Now, according to the rules of this app, a <code>Hero</code> must not be created without at least one <code>Photo</code>. I've spent 4 hours combing the docs and I'm yet to find a solution. If this were Rails, it'd be simple:</p>
  
  <pre><code>class Hero &lt; ActiveRecord::Base
    has_many :photos, dependent: :destroy
  
  class Photo &lt; ActiveRecord::Base
    belongs_to :hero
  </code></pre>
  
  <p>With my Django models, the fields make sure that a <code>Photo</code> can't be uploaded without a <code>Hero</code> — which is what I want — but a <code>Hero</code> can be created without a <code>Photo</code> — which is not what I want, I'd like to enforce at the database level that a <code>Hero</code> has at least one <code>Photo</code>.</p>
  
  <p>How do I achieve that?</p>