当我尝试执行 django models migrate 命令时出现错误 - python manage.py migrate 。如何解决这个错误?
I am getting an error in when i am trying to execute django models migrate command - python manage.py migrate . How to solve this error?
from django.db import models
from django.contrib.auth.models import User
class Student(models.Model):
rollno = models.CharField(max_length=13)
name = models.OneToOneField(User, on_delete=models.CASCADE)
dept = models.CharField(max_length=30)
def __str__(self):
return str(self.name)
class Subject(models.Model):
subname = models.CharField(max_length=50)
deptname = models.CharField(max_length=50)
def __str__(self):
return str(self.subname)
PS C:\Users\Akhil\Desktop\django\studentportal> python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions, studentapp
Running migrations:
Applying studentapp.0003_auto_20210602_0944...Traceback (most recent call last):
File "C:\Users\Akhil\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\fields_init_.py", line 1823, in get_prep_value
return int(value)
ValueError: invalid literal for int() with base 10: 'CSE'
我试图删除我创建的模型。每当我尝试迁移模型时删除后,我都会收到此错误。所以我再次添加了相同的模型主题
您似乎已将数据库中的某个字段更改为 IntegerField
然后又改回来?如果可以擦除数据库,我建议将其删除并迁移,然后重新运行 ./manage.py makemigrations
和 ./manage.py migrate
。
from django.db import models
from django.contrib.auth.models import User
class Student(models.Model):
rollno = models.CharField(max_length=13)
name = models.OneToOneField(User, on_delete=models.CASCADE)
dept = models.CharField(max_length=30)
def __str__(self):
return str(self.name)
class Subject(models.Model):
subname = models.CharField(max_length=50)
deptname = models.CharField(max_length=50)
def __str__(self):
return str(self.subname)
PS C:\Users\Akhil\Desktop\django\studentportal> python manage.py migrate Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions, studentapp Running migrations: Applying studentapp.0003_auto_20210602_0944...Traceback (most recent call last): File "C:\Users\Akhil\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\fields_init_.py", line 1823, in get_prep_value return int(value) ValueError: invalid literal for int() with base 10: 'CSE'
我试图删除我创建的模型。每当我尝试迁移模型时删除后,我都会收到此错误。所以我再次添加了相同的模型主题
您似乎已将数据库中的某个字段更改为 IntegerField
然后又改回来?如果可以擦除数据库,我建议将其删除并迁移,然后重新运行 ./manage.py makemigrations
和 ./manage.py migrate
。