I am storing 'payment' model instance via form POST method but I have the data of the foreign key field already, because I am coming from a page which list the objects of 'student' model. I am storing the field of foreign key by input type="hidden" html element.
but when I submit, it shows error
> Cannot assign "u'1'": "payment.student" must be a "student" instance.
> Request Method: POST
> Django Version: 1.5.2
> Exception Type: ValueError
> Exception Value:
> Cannot assign "u'1'": "payment.student" must be a "student" instance.
> Exception Location: /usr/local/lib/python2.7/dist-> > > > >packages/django/db/models/fields/related.py in __set__, line 405
>Python Executable: /usr/bin/python
>Python Version: 2.7.3
This is my model:
class payment(models.Model):
Id = models.AutoField(primary_key=True)
student = models.ForeignKey('student',db_column='student')
dateTime = models.DateField(auto_now_add=True)
amountDue = models.DecimalField(max_digits=5, decimal_places=2)
I added later added db_column='student'
but it might not have really taken effect in mysql database.