Home > Software engineering >  Error: no such table when extending Abstract User Model
Error: no such table when extending Abstract User Model

Time:10-22

I wanted to extend the Base Abstract User Model within Django to have some other Fields:

class Student(AbstractUser):
    birth = models.DateField(default=datetime.date.today)
    street = models.CharField(max_length=20)
    street_number = models.IntegerField(validators=[MinValueValidator(0), MaxValueValidator(99)])
    city = models.CharField(max_length=20)
    province = models.CharField(max_length=20)
    code = models.IntegerField(validators=[MinValueValidator(0, MaxValueValidator(9999))])
    address = str(street)   str(street_number)   str(city)   str(code)   str(province)

    def __str__(self):
        return f'Adresse: {self.address}'

I added this into my settings.py file:

AUTH_USER_MODEL = 'mainApp.Student'

But I get an Error saying there is no such table "Student" when trying to load /admin/. I have made all the migrations using:

python manage.py makemigrations mainApp
python manage.py migrate mainApp

Error:

OperationalError at /admin/

no such table: mainApp_student

If y'all need any more infos, please comment!

CodePudding user response:

Try in first time to run:

python manage.py makemigrations
python manage.py migrate

Without put the app name to migration process

CodePudding user response:

You cannot define "address" like this. Database column is not for string concatenation of other columns, nor any calculation. It can cause error.

  • Related