title: How do I access auth User's User.objects.create_user(...) in a south migration?
body: <p>Instead of using django's auth module I've used my own and already regret it a lot.</p>
  
  <p>In an effort to rectify the situation, I'm trying to migrate the data from my User model to django.auth.models.User.</p>
  
  <p>I've created a data migration as follows:</p>
  
  <pre><code>def forwards(self, orm):
      """Migrate user information from mooi User model to auth User model."""
  
      OldUser = orm['mooi.User']
      User = orm['auth.User']
      Profile = orm['mooi.Profile']
  
      oldUsers = OldUser.objects.all()
      for oldUser in oldUsers:
          newUser = User.objects.create_user(username=oldUser.id, email=oldUser.email, password=oldUser.password)
          # ...more irrelevant code follows...
  </code></pre>
  
  <p>When I run the migration, I get this error (traceback):</p>
  
  <pre><code>#...irrelevant traceback precedes...
  File "[projdir]/mooi/migrations/0005_from_mooi_users_create_auth_users_with_profiles.py", line 18, in forwards
      newUser = User.objects.create_user(username=oldUser.id, email=oldUser.email, password=oldUser.password)
    File "[virtual_env_dir]lib/python2.6/site-packages/south/orm.py", line 397, in __getattr__
      return getattr(self.real, name)
  AttributeError: 'Manager' object has no attribute 'create_user'
  </code></pre>
  
  <p>Upon further investigation, I discovered that the <code>Manager</code> that was being referred to was of time <code>south.orm.NoDryRunManager</code> which explains the error.</p>
  
  <p>Now, the reason I even need <code>create_user</code> is to create a password hash that <code>django.contrib.auth</code> will understand.</p>
  
  <p>Having said all that, how do I go about doing this? What's the most elegant solution given the hole I'm in?!</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>Update 1</strong></p>
  
  <p>As suggested by <a href="https://stackoverflow.com/users/79225/stevejalim">stevejalim</a>, I tried to use <code>User</code>'s <code>set_password(...)</code> as follows:</p>
  
  <pre><code>newUser.set_password(raw_password=oldUser.password)
  newUser.save()
  </code></pre>
  
  <p>However that failed with this error:</p>
  
  <pre><code>File "[projdir]/mooi/migrations/0005_from_mooi_users_create_auth_users_with_profiles.py", line 21, in forwards
      newUser.set_password(raw_password=oldUser.password)
  AttributeError: 'User' object has no attribute 'set_password'
  </code></pre>
  
  <p>I did find a hint in the <a href="http://south.aeracode.org/docs/ormfreezing.html#rationale-behind-the-serialisation" rel="nofollow noreferrer">south documentation</a> which states that:</p>
  
  <blockquote>
    <p>South doesn’t freeze every aspect of a
    model; for example, <strong>it doesn’t
    preserve new managers, or custom model
    methods</strong>, as these would require
    serialising the python code that runs
    those method (and the code that
    depends on, and so forth).</p>
    
    <p>If you want custom methods in your
    migration, <strong>you’ll have to copy the
    code in, including any imports it
    relies on to work</strong>. Remember, however,
    for every import that you add, you’re
    promising to keep that import valid
    for the life for the migration.</p>
  </blockquote>
  
  <p>I guess the question remains, what's the best/safest way of doing this? Copy the <code>set_password(...)</code> method over? Create a function that hashes the password for me? Any other ideas?</p>