[英]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' 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最后调用):文件“C:\Users\Akhil\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\fields_init _.py ”,第 1823 行,在 get_prep_value 返回int(value) ValueError: int() 以 10 为底的无效文字:'CSE'
I tried to delete a model which I have created.我试图删除我创建的 model。 After deleting whenever I try to migrate the model, I am getting this error.每当我尝试迁移 model 时删除后,我都会收到此错误。 So I added the same model Subject again所以我再次添加了相同的 model 主题
It looks like you've changed a field in your database to an IntegerField
and back again?看起来您已将数据库中的字段更改为IntegerField
并再次返回? If the database can be wiped, I suggest deleting it, and migrations, and then rerunning ./manage.py makemigrations
and ./manage.py migrate
.如果可以擦除数据库,我建议将其删除,然后迁移,然后重新运行./manage.py makemigrations
和./manage.py migrate
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.