Cannot assign "'10000'": "Jobs.client_id" must be a "Clients" instance
I have two tables, Jobs and Clients.
class Jobs(models.Model):
client_id = models.ForeignKey(Clients,db_column='client_id',on_delete=models.CASCADE)
class Clients(models.Model):
created = models.DateTimeField()
modified = models.DateTimeField(auto_now=True)
I have Jobs data in json format.
jobs_data = {
'client_id':'10000',
....
}
When I want to save this data into Jobs table I get the ValueError: Cannot assign "'10000'": "Jobs.client_id" must be a "Clients" instance.
To save the table I have tried
jobs_obj = Jobs.objects.create(**v['Job'])
I also tried -
client_obj = Clients.objects.get(id=v['Job']['client_id'])
jobs_obj = Jobs.objects.create(**v['Job'],Clients=client_obj)
How can I fix this problem ?