Search code examples
pythondjangodjango-modelsdjango-admin

"no such column: id" Django AbstractUser model


I am trying to migrate, and view the admin page. both makemigrations and migrate passed, yet when i go to the admin url it reads this: "django.db.utils.OperationalError: no such column: social_app_user.id"

And once i create an id field, it changes to "django.db.utils.OperationalError: no such column: social_app_user.password"

I was under the impression that the AbstractUser model included all the default user fields, not sure about the primary key, but regardless.

Please help, thanks!

Note: the 'id' field in this models.py file was added after i got the error.

from django.contrib.auth.models import AbstractUser, UserManager
from django.db import models

class User(AbstractUser):
    is_verified = models.BooleanField(default=True)
    id= models.AutoField(primary_key=True, null=False)
    REQUIRED_FIELDS = []

    objects =  UserManager()

    def __str__(self):
        f"{self.username} {self.email}"
        return


class main_feed(models.Model):
    content= models.CharField(unique=True, max_length=255, default='', null=False)
    poster = models.ForeignKey('User', related_name='author', on_delete=models.CASCADE, to_field='username')
    likes = models.IntegerField(default=0, null=False)
    favorites = models.IntegerField(default=0, null=False)
    date_posted = models.DateTimeField(auto_now=True)

    def __str__(self):
        f"{self.content} {self.likes} {self.poster} {self.date_posted}"
        return

Solution

  • It turns out I had to restart my entire application and run startapp again. This time i added the user model and set up the settings and admin file BEFORE the very first migration. then everything works dandy. But I have no idea why this is the case, shouldnt the migration update and override the default user model? anyways the question is answered now.