P Sai Akhil
P Sai Akhil

Reputation: 1

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'

I tried to delete a model which I have created. After deleting whenever I try to migrate the model, I am getting this error. So I added the same model Subject again

Upvotes: 0

Views: 611

Answers (1)

Tom Hamilton Stubber
Tom Hamilton Stubber

Reputation: 767

It looks like you've changed a field in your database to an IntegerField and back again? If the database can be wiped, I suggest deleting it, and migrations, and then rerunning ./manage.py makemigrations and ./manage.py migrate.

Upvotes: 1

Related Questions