[英]Profile table not being created for extended User model in django
我在 django 中遇到了這個問題,即使我的 models.py 文件中有一個配置文件 model,它擴展了 django 用戶 model 仍在運行“makemigration”和“migrate”命令,但配置文件表未在數據庫中生成。
這是我的模型.py:
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
clg_name = models.CharField(max_length=200)
class Student(models.Model):
name = models.CharField(max_length=100, blank=False)
enrollment_number = models.IntegerField(unique=True, null=True, blank=False)
clg_name = models.CharField(max_length=200, blank=False)
program_name = models.CharField(max_length=30, blank=False)
class Result(models.Model):
student = models.ForeignKey(Student, on_delete=models.CASCADE)
sem = models.IntegerField()
exam_name = models.CharField(max_length=30)
percnt = models.FloatField(null=True)
cgpa = models.FloatField(null=True)
class Marks(models.Model):
result = models.ForeignKey(Result, on_delete=models.CASCADE)
course_name = models.CharField(max_length=100, null=True)
course_code = models.IntegerField(null=True)
course_credit = models.IntegerField(null=True)
grade = models.FloatField(null=True)
這是 output 的py manage.py makemigration 帳戶:
Migrations for 'account':
account\migrations\0001_initial.py
- Create model Result
- Create model Profile
- Create model Marks
這是py manage.py migrate的 output:
Operations to perform:
Apply all migrations: account, admin, auth, contenttypes, sessions
Running migrations:
No migrations to apply.
我不知道您的帳戶應用程序有什么問題。 但你可以解決它:
1-刪除位於帳戶應用程序內__pycache__
和migrations
文件夾
2 - 運行python manage.py makemigrations account zero
3 - 然后運行python manage.py makemigrations account
4 - 最后運行python manage.py migrate
我通過刪除整個數據庫並刪除我的應用程序的 py_cache 和遷移文件解決了以下錯誤。 只需創建另一個數據庫並重新運行遷移和遷移命令即可。 希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.