[Answer]-Python populating a database with one-to-many relationship

1👍

u.instrumentCategory = 1

That’s not how a models.ForeignKey field works in Django. You need to get an instance of the Category object and assign that to u.instrumentCategory.

u.instrumentCategory = pmod.Category.objects.get(id=1)

0👍

You may try :

u.instrumentCategory_id = 1

Leave a comment