Home > Enterprise >  django.db.utils.OperationalError: no such column: authentication_user.name
django.db.utils.OperationalError: no such column: authentication_user.name

Time:08-26

I was trying to add a new field to my User authentication model. But whenever I'm trying to run python manage.py makemigrations, the console is showing,

django.db.utils.OperationalError: no such column: authentication_user.name

Here is a part of my Model:

class User(AbstractBaseUser, PermissionsMixin):

    id = models.UUIDField(primary_key=True, max_length=36, default=uuid.uuid4, 
                          editable=False,blank=False, null=False)
    cus_id = models.CharField(max_length = 250, null=True, blank=True, 
                              default=increment_cus_number)
    email = models.EmailField(max_length=255, unique=True, db_index=True)
    username = models.CharField(max_length=250, blank = True, null = True)
    name = models.CharField(max_length=250, default = '', blank = True, null = True)
    first_name = models.CharField(max_length=250, blank=True, null=True)
    last_name = models.CharField(max_length=250, blank=True, null=True)
    mobile = models.CharField(max_length = 100, null = True)
    date_of_birth = models.DateField(blank=True, null=True)
    address = models.TextField(blank=True, null=True)
    picture = models.ImageField(blank=True, null=True)
    gender = models.CharField(max_length=100, blank = True, null= True)
    is_verified = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)
    business_partner = models.BooleanField(default=False)
    is_staff = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    auth_provider = models.CharField(
        max_length=255, blank=False,
        null=False, default=AUTH_PROVIDERS.get('email'))

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = UserManager()

    def __str__(self):
        return self.email

any suggestions/tips regarding this issue would be a great help.

CodePudding user response:

Try running:

py manage.py migrate

It seems the columns in the database have not been created yet. If that doesn't work:

  • Delete migration files from your project, folder structure for migrations should look like this after clearing:
/migrations
    /__init__.py
  • Makemigrations to re-generate the migrations.
  • Migrate to create all nescessary DB tables, columns, etc.

CodePudding user response:

May be use are calling User.name in some where. When we start server django will check that coloum in database that may not migrated at our database. One solution is try to find out where you called that User.name and use corroct login. or try dropping the database and all migrations files. migrate again

AFTER DROPPING DATABASE

find . -path "*/migrations/*.py" -not -path "*/venv/*" -not -name "__init__.py" -delete
find . -path "*/migrations/*.pyc" -not -path "*/venv/*" -delete
python manage.py makemigrations
python manage.py migrate
  • Related