**models.py**
i have create foreignkey in table paymentsDetails i have stripe payment method which is working when user login session is created and by using session value i get the primarykey of that user by using 'ORM' method and then assign this primary key of specific user into the paymentdetails models field named as user\_account\_id
but i am getting error that i cannot assign 1 to PaymentsDetail.User\_account\_id must be a instance of UserAccountModel

```
class UserAccountModel(models.Model):

ContactEmail = models.EmailField(max_length=30)
FirstName = models.CharField(max_length=30)
LastName = models.CharField(max_length=40)
Counrty = models.CharField(max_length=50)
Phone = models.IntegerField()
ChooseUserName = models.CharField(max_length=30)
password = models.CharField(max_length=32)
EnterCaptcha = models.CharField(max_length=4)
payments = models.BooleanField(max_length=6, default=False)
showsponsor = models.CharField(max_length=30, default=False)
RegisteredDate = models.DateTimeField(auto_now_add=True, blank=True)
ActivationOn = models.DateField(auto_now_add=False,blank=True)
expiry_date = models.DateField(auto_now_add=False,blank=True)
def __str__(self):
    return self.FirstName + ":" + self.ChooseUserName

class PaymentsDetail(models.Model):

refrer_name = models.CharField(max_length=32,default="", editable=False)
sponser_name = models.CharField(max_length=32)
status = models.CharField(default='comped', max_length=32)
s_id = models.CharField(max_length=32)
registered = models.DateTimeField(auto_now_add=True)
activated_date = models.DateField(auto_now_add=False)
Due_Date = models.DateField(auto_now_add=False)
payment = models.CharField(default='$',max_length=32)
User_Account_id = models.ForeignKey(UserAccountModel, on_delete=models.CASCADE, default=True, editable=True)

addprogrameReference = models.ForeignKey(AddProgramModel, on_delete=models.CASCADE, default=True, editable=True)

class Meta:
    ordering = ['User_Account_id', 'addprogrameReference']

```

def **str**(self):
 return self.refrer\_name + ":" + self.user\_account

> 
> i am getting the error
> 
> 
> cannot assign 1 to PaymentsDetail.User\_account\_id must be a instance
>  of UserAccountModel
> 
> 
> 

**views.py**

```
                print("user payment"+str(charge.amount))
                pays = str(charge.amount)
                user_id = random.randint(0, 999)  # returns a random integer
                user = User.objects.get(username=str(rerredby))
                userKey = user.pk
                print("this one is for user upper")
                # saving record
                payment_insertion = PaymentsDetail.objects.create(
                    User_Account_id=userKey,
                    refrer_name=rerredby,
                    sponser_name=rerredby,
                    s_id=str(user_id),
                    registered=datetime.now(),
                    activated_date=datetime.now(),
                    Due_Date=datetime.now(),
                    payment=str(pays + "$"),
                )
                payment_insertion.save()

```