title: django custom command complains AssertionError: ForeignKey(None) is invalid. why
body: <p>I've followed django custom command tutorial, the link is <a href="https://docs.djangoproject.com/en/dev/howto/custom-management-commands/" rel="nofollow">here</a>.</p>
  
  <p>My working directory looks like this:</p>
  
  <pre><code>myapps/
      __init__.py
      models.py
      management/  
          __init__.py
          commands/
              __init__.py
              my_command.py
      tests.py
      views.py
  </code></pre>
  
  <p>My code looks like this:</p>
  
  <pre><code>from django.core.management.base import BaseCommand, CommandError
  
  class Command(BaseCommand):
  
      def handle(self, *args, **options):
          print '=========='
          self.stdout.write('Successfully closed poll ttt')
  </code></pre>
  
  <p>When I run the command manage.py my_command, I got the following errors, </p>
  
  <pre><code>  File "D:/ERP\apps\person\salary\models.py", line 8, in &lt;module&gt;
      class Salarys(models.Model):
    File "D:/ERP\apps\person\salary\models.py", line 14, in Salarys
      Unit = models.ForeignKey(Units, verbose_name = u'def_unit, on_delete = models.PROTECT) 
    File "D:\Python27\Lib\site-packages\django\db\models\fields\related.py", line 910, in __init__
      assert isinstance(to, basestring), "%s(%r) is invalid. First parameter to ForeignKey must be either a model, a model name, or the string %r" % (self.__class__.__name__, to, RECURSIVE_RELATIONSHIP_CONSTANT)
  AssertionError: ForeignKey(None) is invalid. First parameter to ForeignKey must be either a model, a model name, or the string 'self'
  </code></pre>
  
  <p>Obviously, the first parameter of ForeignKey is my model Units, how do I silence the compiler's complaint?</p>
  
  <p>ps: my model looks like this:
  my model looks like this now.</p>
  
  <pre><code>class Salarys(models.Model):
      '''
      describe : salary table
      author : liyang 2013-1-23
      '''
      User = models.ForeignKey(Users, verbose_name = u'account', on_delete = models.PROTECT) 
      Unit = models.ForeignKey(Units, verbose_name = u'def_unit', on_delete = models.PROTECT, null=True) 
      yy = models.IntegerField(u'year)
      mm = models.IntegerField(u'month')
      class Meta:
          db_table = 'users_salarys'
  
  class Units(models.Model):
      '''
      describe : def unit model
      author : liyang 2012-12-4 11:45
      '''
      name = models.CharField(u'name',max_length = 20) 
      cname = models.CharField(u'company name',max_length = 20, blank = True, null = True) 
      aname = models.CharField(u'company short cut',max_length = 20, blank = True, null = True)         
      telephone = models.CharField(u'contact',max_length = 20, blank = True, null = True)         
      website = models.CharField(u'website',max_length = 25, blank = True, null = True)         
      address = models.CharField(u'address',max_length = 50, blank = True, null = True)         
      class Meta:
          db_table = 'units'
  </code></pre>
  
  <p>....</p>
  
  <p>the strange things are </p>
  
  <p>1: User foreignkey does not make any troubles while Unit does...</p>
  
  <p>2: my web server can be run without any problem while the command line can not be run...</p>