I had a field in my model with
book_classes = (("","Select Form"),("1",'F1'),("2",'F2'),("3",'F3'),("4",'F4'),("All Forms","All Forms"))
b_classes = models.CharField('Form',max_length=9,choices=book_classes,default="n/a")
And then changed it to
b_class =models.ForeignKey(ClassBooks,on_delete=models.CASCADE)
Where
class ClassBooks(models.Model):
name = models.CharField(max_length=10)
I'm now stuck because when I try to migrate I get an error.
Invalid input syntax for type bigint:"All Forms"
Makemigrations and migrate worked well in development. When I pushed to digital ocean, the migrate returned the error stated. What do I need to do, please?
See Foreign Key field. By default a FK field is going to use the Primary Key of the referenced table(model), in this case the
idfield ofClassBooks. Theidfield is an integer so you get the error when trying to use a string field. To make this work, from the documentation link :Which in your case becomes:
This assumes that the
namefield has aUniqueconstraint on it.Though I am not sure how
"", "1", "2" ...map toClassBooks.name.