[Django]-Cannot assign "<class 'django.contrib.auth.models.User'>": "Model.user" must be a "User" instance

7👍

You see this error because you are trying to assing class object to author attribute. But it suppose to be User instance. So you should create user record first and use it, something like this instead:

user = User.objects.create_user(username="name", email="email@mail.com", password="Pass12345")
post_1 = Post(name="testname", email="testemail", gender="Monsieur", number="23233", author=user)

You can think about model class as about database table. While model instance represents record from this table.

Leave a comment