ValueError: invalid literal for int() with base 10:

You must supply a user when you create a department. You can access the current user as request.user if you are in a view

user = request.user 

or fetch any user from the database if you are testing in the shell

user = User.objects.get(id=1) # get 

then create the department:

department = Department(name="test",
                        description='test',
                        user=user,
                        )

Finally, your default=User.pk is incorrect. For a user instance you can access user.pk, but the class attribute User.pk is not pk of the current user as you might think it is.

Leave a Comment