Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

i get this error OperationalError at /admin/accounts/student/

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading