Django运行服务器报错:type object 'Teachprofile' has no attribute '_meta' 求助
解决Django中AttributeError: type object 'Teachprofile' has no attribute '_meta'错误
你的Teachprofile类没有继承Django的models.Model基类,这导致它不是合法的Django模型——既没有Django模型核心的_meta元数据属性,也无法执行迁移操作。
修改后的Models.py代码
from django.db import models from django.contrib.auth.models import User class Teachprofile(models.Model): owner=models.ForeignKey(User,on_delete=models.CASCADE,default=1) name=models.CharField(max_length=51) DOB=models.DateField() Address=models.TextField() Place=models.CharField(max_length=51) City=models.CharField(max_length=51) State=models.CharField(max_length=51) course=models.ForeignKey(Courses,on_delete=models.CASCADE,default=1)
后续操作步骤
- 保存修改后的
models.py文件 - 执行迁移命令:
python manage.py makemigrations python manage.py migrate - 重新启动Django服务器
内容的提问来源于stack exchange,提问作者Muhammad Asif
相关产品推荐
相关产品推荐

