Home > other >  i get this error OperationalError at /admin/accounts/student/
i get this error OperationalError at /admin/accounts/student/

Time:04-15

hey guys i work withe django framework i had the error OperationalError

i have to class with same fields

class Student(models.Model):
    user = models.OneToOneField(User, null=True, blank=True, on_delete=models.CASCADE)
    id = models.AutoField(primary_key=True)
    First_Name = models.CharField('First Name', max_length=30, null=True, blank=True)
    Last_Name = models.CharField('Last Name', max_length=30, null=True, blank=True)
    ID_Number = models.CharField('Id Number', max_length=30, null=True, blank=True)
    Phone = PhoneNumberField('Phone',null=True)
    
    class Meta:
        verbose_name_plural = "Students"

    def __str__(self):
        return str(self.user)

class Lecturer(models.Model):
    user = models.OneToOneField(User, null=True, blank=True, on_delete=models.CASCADE)
    id = models.AutoField(primary_key=True)
    First_Name = models.CharField('First Name', max_length=30, null=True, blank=True)
    Last_Name = models.CharField('Last Name', max_length=30, null=True, blank=True)
    ID_Number = models.CharField('Id Number', max_length=30, null=True, blank=True)
    Phone = PhoneNumberField('Phone',null=True)
    
    class Meta:
        verbose_name_plural = "Lecturers"

    def __str__(self):
        return str(self.user)

and i add new field to my Student and also to Lecturer classes the field is

Phone = PhoneNumberField('Phone',null=True)

and yes i did the commands:

python manage.py makemigrations 
python manage.py migrate

after that i get prove that every thing is update:

Operations to perform:
  Apply all migrations: HomePage, accounts, admin, auth, contenttypes, sessions
Running migrations:
  No migrations to apply.

but when i run the runserver and after the i go to the url

http://localhost:8000/admin

add i go the Lecturers data every things work great i have new field Phone Lecturers but when i try to go Student data i get Error and don't recognize the fields phone!

Student Error

CodePudding user response:

If you dont want to lose db.sqlite3 try to delete migrations first

Step 1: Delete the db.sqlite3 file.

Step 2 : $ python manage.py migrate

Step 3 : $ python manage.py makemigrations

Step 4: Create the super user using $ python manage.py createsuperuser

new db.sqlite3 will generates automatically

Take a look to this entry

  • Related