In Django I am getting an Integrity Error while testing to create an object

In my Django REST API project I am getting an Integrity Error when I run my tests.

class Tag(models.Model):
    """Tag for filtering recipes."""
    name = models.CharField(max_length=255)
    user = models.ForeignKey(

    def __str__(self):

And here is my test that fails:

def test_create_tag(self):
    user = get_user_model().objects.create_user(email="",password="password123")
    tag = models.Tag.objects.create(user=user, name="Tag1")


This is the error that I have been getting:

Traceback (most recent call last):
File "/app/core/tests/", line 80, in test_create_tag
tag = models.Tag.objects.create(user=user, name="Tag1")

django.db.utils.IntegrityError: null value in column "user_id" of relation "core_tag" violates not-null constraint DETAIL: Failing row contains (1, Tag1, null).

Why while this test running creates an error?

Back to Top