Django项目 /管理员 /途径

发布于 2025-01-22 00:01:43 字数 2090 浏览 4 评论 0原文

嘿,我使用Django框架,我有错误OperationationalRor

我有两个类别的课程:

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)

我为我的学生添加了一个新字段,也为讲师课程添加了该字段

  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.

但是当我运行 runserver 之后,我转到管理员路线:

http:// localhost:8000/admin

很好,我有新的现场电话:

添加我去讲师数据,一切都 当我尝试获取学生数据时,我会遇到错误,并且无法识别该字段的手机!

“学生错误”

Hey I work with django framework I had the error OperationalError.

I have two classes with the 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 a 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 am sure that everything is updated:

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 that, I go to the admin route:

http://localhost:8000/admin

add I go the Lecturers data everything work great I have new field Phone:

Lecturers

But when I try to go to Student data I get an Error and don't recognize the field's phone!

Student Error

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

-小熊_ 2025-01-29 00:01:43

如果您不想丢失db.sqlite3尝试删除迁移的第一步

1:删除db.sqlite3 file。

步骤2:$ Python Manage.py Migrate

步骤3:$ Python Manage.py Makemigrations

步骤4:使用$ python Manage.py createSuperuser

db.sqlite3将自动生成。

看这个条目

If you don't 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 a superuser using $ python manage.py createsuperuser

new db.sqlite3 will generate automatically.

Take a look at this entry

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文