I was trying to run my Django App with PostgreSQL as my database engine. I'm getting a template rendering error from the template loader after deployment. It's for the form I created using ModelChoiceField.
And also while migrating I get an error saying
django.db.utils.ProgrammingError: column "category_parent" cannot be cast automatically to type integer HINT: You might need to specify "USING category_parent::integer".
I believe the returning of index from the select field is causing the problem. Is it possible to resolve this without much trouble.
This is the class for that form.
class CategoryForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(CategoryForm, self).__init__(*args, **kwargs)
self.fields['category_parent'].required = False
category_parent = forms.ModelChoiceField(
queryset=Category.objects.all(), empty_label='None')
category_image = forms.ImageField()
class Meta:
model = Category
fields = ('category_name', 'category_code',)
Screenshot of the template error I'm getting.
My model class for the same
class Category(models.Model):
category_name = models.CharField(max_length=300)
category_code = models.CharField(max_length=100)
category_parent = models.ForeignKey('self', blank=True, null=True)
category_image = models.ImageField(upload_to='category')
def __str__(self):
return self.category_name
Screenshot of error from my terminal screen
Please help. Thanks in advance.