[Fixed]-Save a foreign key in postgreSQL using python-django

0👍

Remove to_field='nom' from the nomTreballador ForeignKey field and it will insert the Treballador‘s primary key (an integer) instead of nom (which is a string).

1👍

Your foreign key field is the problem.
Remove to_field and Django will automatically map it to ID

nomTreballador = models.ForeignKey(treballador)

Leave a comment