简体   繁体   English

当我尝试执行 django 模型迁移命令时出现错误 - python manage.py 迁移。 如何解决这个错误?

[英]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.

相关问题 我是 django 的新手,当我尝试 python manage.py runserver 时......我在下面收到一个错误......我现在必须做什么? 请让我知道 - I am new to django and when I am trying to python manage.py runserver... I was getting an error below... what I have to do now? please let me know 当我在models.py中的python django中运行此命令python manage.py makemigrations博客时出错 - Error when I run this command python manage.py makemigrations blog in python django in models.py 当我运行 >> python manage.py sqlmigrate travello 0001 命令时,我正在处理 django 项目,它显示以下错误帮助 - I am working on django project when i run >> python manage.py sqlmigrate travello 0001 command it show the following error help on this 运行命令manage.py migration时出错 - Error in running command manage.py migrate Django manage.py 迁移错误 - Django manage.py migrate error 命令$ python3 manage.py migration错误 - Error with command $python3 manage.py migrate Django,在manage.py检查或sync.db时出现“错误:模块:无法导入模型” - Django, I am getting “ERROR: Module: models could not be imported” while manage.py check or sync.db python3 django manage.py迁移错误_gorg - python3 django manage.py migrate error _gorg python manage.py迁移着陆错误 - python manage.py migrate landing error 如何修复尝试迁移manage.py的错误 - How to fix error trying to migrate manage.py
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM