title: AbstractUser Django full example
body: <p>I am new to Django and I have been trying this for weeks, but could not find a way to solve this problem.</p>
  
  <p>I want to store additional information like user mobile number, bank name, bank account. And want to store the mobile number while user registers and wants user to login with either (mobile number and password) or (email and password).</p>
  
  <p>This is my UserProfile model</p>
  
  <pre><code>from django.db import models
  from django.contrib.auth.models import User
  from django.contrib.auth.models import AbstractUser
  # Create your models here.
  
  class UserProfile(AbstractUser):
  
       user_mobile = models.IntegerField(max_length=10, null=True)
       user_bank_name=models.CharField(max_length=100,null=True)
       user_bank_account_number=models.CharField(max_length=50, null=True)
       user_bank_ifsc_code = models.CharField(max_length=30,null=True)
       user_byt_balance = models.IntegerField(max_length=20, null=True)
  </code></pre>
  
  <p>And this is my forms.py</p>
  
  <pre><code>from django import forms            
  from django.contrib.auth.models import User   # fill in custom user info then save it 
  from django.contrib.auth.forms import UserCreationForm      
  from models import UserProfile
  from django.contrib.auth import get_user_model
  
  class MyRegistrationForm(UserCreationForm):
      email = forms.EmailField(required = True)
      mobile = forms.IntegerField(required=True)
  
  
  
      class Meta:
          model = UserProfile
          fields = ('username', 'email', 'password1', 'password2','mobile' )        
  
      def save(self,commit = False):   
          user = super(MyRegistrationForm, self).save(commit = False)
          user.email = self.cleaned_data['email']
          user.user_mobile = self.cleaned_data['mobile']
          user.set_password(self.cleaned_data["password1"])
  
          user_default = User.objects.create_user(self.cleaned_data['username'],
                                                  self.cleaned_data['email'],
                                                  self.cleaned_data['password1'])
          user_default.save()
  
          if commit:
               user.save()
  
           return user
  </code></pre>
  
  <p>In my settings.py I have included</p>
  
  <pre><code>AUTH_USER_MODEL = "registration.UserProfile"
  </code></pre>
  
  <p>admin.py of my app is </p>
  
  <pre><code>from django.contrib import admin
  from django.contrib.auth.admin import UserAdmin
  from django.contrib.auth.models import User
  from models import UserProfile
  
  class UserProfileInline(admin.StackedInline):
      model = UserProfile
      can_delete = False
      verbose_name_plural = 'userprofile'
  
   class UserProfileAdmin(UserAdmin):
      inlines = (UserProfileInline, )
  
   admin.site.register(UserProfile, UserProfileAdmin)
  </code></pre>
  
  <p>While adding the user from admin I get this error</p>
  
  <pre><code>Exception at /admin/registration/userprofile/1/
  &lt;class 'registration.models.UserProfile'&gt; has no ForeignKey to &lt;class 'registration.models.UserProfile'&gt;
  </code></pre>
  
  <p>Can someone help me with this or point out to the full working exapmle, I have seen Django documentation but didn't find any luck. Or if there is another way to do this.</p>
  
  <p>Thanks in advance</p>
  
  <p>Edit 1:</p>
  
  <p>While registering from the registration form I'm also getting this error</p>
  
  <pre><code>DatabaseError at /register
  (1146, "Table 'django_auth_db.auth_user' doesn't exist")
  </code></pre>