Django model migration added two unwanted fields when using AbstractBaseUser class
<p>Django 1.9<br>
Python 3.4   </p>

<p>I created a custom Users model using AbstractBaseUser class. Below is the code.</p>

<pre><code>class UserModel(AbstractBaseUser):
    # custom user class
    SYSTEM = 0
    TENANT = 1
    parent_type_choices = (
                           (SYSTEM, 'System'),
                           (TENANT, 'Tenant')
                           )
    sys_id = models.BigIntegerField(primary_key=True, blank=False)
    parent_type = models.PositiveIntegerField(choices=parent_type_choices, null=False, blank=False)
    parent_sys_id = models.ForeignKey('tenant.TenantModel', on_delete = models.SET_NULL, null=True, blank=True)
    last_name = models.CharField(null=False, blank=False, max_length=40)
    first_name = models.CharField(max_length=40, null=False, blank=False)
    display_name = models.CharField(max_length=80, unique=True, null=False, blank=False)
    login = models.CharField(max_length=40, unique=True, null=False, blank=False)
    authentication_method = models.CharField(max_length=80)
    pwd = models.CharField(max_length=40)
    access_valid_start = models.DateTimeField()
    access_valid_end = models.DateTimeField()
    created_when = models.DateTimeField()
    created_by = models.BigIntegerField()
    last_updated_when = models.DateTimeField()
    last_updated_by = models.BigIntegerField()
    notes = models.CharField(max_length=2048)

    USERNAME_FIELD = "login"

    class Meta:
        app_label = "accounts"
        db_table = "Users"
</code></pre>

<p>When I migrated the changes, table was created in db with two extra fields which I didn't defined. <code>Password</code> and <code>last_login</code> were added.  </p>

<pre><code>desc Users;
+-----------------------+------------------+------+-----+---------+-------+
| Field                 | Type             | Null | Key | Default | Extra |
+-----------------------+------------------+------+-----+---------+-------+
| password              | varchar(128)     | NO   |     | NULL    |       |
| last_login            | datetime         | YES  |     | NULL    |       |
| sys_id                | bigint(20)       | NO   | PRI | NULL    |       |
| parent_type           | int(10) unsigned | NO   |     | NULL    |       |
| last_name             | varchar(40)      | NO   |     | NULL    |       |
| first_name            | varchar(40)      | NO   |     | NULL    |       |
| display_name          | varchar(80)      | NO   | UNI | NULL    |       |
| login                 | varchar(40)      | NO   | UNI | NULL    |       |
| authentication_method | varchar(80)      | NO   |     | NULL    |       |
| pwd                   | varchar(40)      | NO   |     | NULL    |       |
| access_valid_start    | datetime         | NO   |     | NULL    |       |
| access_valid_end      | datetime         | NO   |     | NULL    |       |
| created_when          | datetime         | NO   |     | NULL    |       |
| created_by            | bigint(20)       | NO   |     | NULL    |       |
| last_updated_when     | datetime         | NO   |     | NULL    |       |
| last_updated_by       | bigint(20)       | NO   |     | NULL    |       |
| notes                 | varchar(2048)    | NO   |     | NULL    |       |
| parent_sys_id_id      | bigint(20)       | YES  | MUL | NULL    |       |
+-----------------------+------------------+------+-----+---------+-------+
</code></pre>

<p>Why this happened? How to remove these fields?</p>

<p>You inherited from <code>AbstractBaseUser</code> class which provides these fields. You can not remove them. Check <a href="https://docs.djangoproject.com/es/1.9/topics/auth/customizing/#specifying-a-custom-user-model" rel="nofollow">Django doc</a> for more info</p>

python mysql django django-models