Django - Foreign Key must be an instance

前端 未结 2 547
[愿得一人]
[愿得一人] 2021-01-11 16:59

I\'ve a model

from django.contrib.auth.models import User

class ModelA(models.Model):
    phone = models.CharField(max_length=20)
    user = models.ForeignK         


        
2条回答
  •  伪装坚强ぢ
    2021-01-11 17:41

    As can be seen in my historic comments, the accepted answer is not really correct. So as @yekta requested I re-submit my comments:

    To create the parent model, use integer value like:

    ModelA.objects.create(phone=data['phone'], user_id=1)
    

提交回复
热议问题