'Django ValueError for deleted fields when running migrations
My models.py
file is as follows:
from django.db import models
from django.utils import timezone
from random import randint
# Create your models here.
class File(models.Model):
fileName = models.CharField(max_length = 30)
description = models.CharField(max_length = 100)
dateUploaded = models.DateTimeField(default = timezone.now)
doc = models.FileField(default = None)
serial = models.CharField(max_length = 6, default = randint(100000000, 999999999), unique = True)
id = models.AutoField(primary_key=True)
I used to have code = models.CharField(default = 'A13S34', max_length = 6, unique = True
but it kept giving the error ValueError: Field 'code' expected a number but got '236E96'.
Thus, I replaced it with the serial field.
However, now when I try to makemigrations
and migrate
, I get the same error ValueError: Field 'code' expected a number but got '236E96'.
What can I do when I no longer even have the code field?
Solution 1:[1]
As @asiniy has mentioned, the previous migration is still there. You may:
Delete the previous (or all) migration file from '/migrations' folder
Run migrations and migrate.
If there are still errors, you may consider clear all models in DB by
Comment out all your model in models.py
Run migrations and migrate
Add back the correct models and redo the migration and migrate
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Xuzheng Lin |