Answer the question
In order to leave comments, you need to log in
How to fix FOREIGN KEY constraint failed error?
There are two models
class User(models.Model):
username = models.CharField(max_length=50)
email = models.CharField(max_length=100)
password = models.CharField(max_length=50)
class Topic(models.Model):
title = models.CharField(max_length=100)
description = models.TextField()
creator = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
Topic.objects.create(title=title, description=description, creator_id=user.id)
FOREIGN KEY constraint failed
request.user.id
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question