我在 /admin/accounts/student/ 处收到此错误 OperationalError

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

大家好,我在使用 Django 框架时遇到错误 OperationalError

我必须 class 使用相同的字段

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)

并且我向我的学生和讲师添加了新字段 classes 该字段是

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

是的,我执行了命令:

python manage.py makemigrations 
python manage.py migrate

之后我证明每件事都是更新的:

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

但是当我 运行 进入 运行 服务器后,我转到 url

http://localhost:8000/admin

添加我去讲师数据每件事都很好我有新领域Phone 但是当我尝试访问学生数据时出现错误并且无法识别字段 phone!

如果你不想丢失 db.sqlite3,请先尝试删除迁移

第 1 步:删除 db.sqlite3 文件。

第 2 步:$pythonmanage.py迁移

第 3 步:$pythonmanage.pymakemigrations

第 4 步:使用 $pythonmanage.pycreatesuperuser

创建超级用户

新的db.sqlite3会自动生成

Take a look to this entry