Skip to content
Advertisement

Django TypeError: id() takes exactly one argument (0 given)

So I have been trying to implement a way to upload multiple images to a post. The way I did it is to have tables. One for the actual post, and one of the multiple images uploaded. I was planning to link them with a foreign key but it is not working. My terminal started throwing the error “TypeError: id() takes exactly one argument (0 given)” . It throws me this error whenever I migrate it.

I am not sure how to fix this.

MY code:

models.py

JavaScript

The errorlog

JavaScript

I use a MySQL database for this. This error started popping up after I updated my tables to be able to link with each other. I plan the fk_post of the P_Images to contain the feature_image value of Projects for the foreign key.

005_migration.py

JavaScript

please let me know if the migration.py tells you something or nothing.

Advertisement

Answer

You have something very bizarre in your migration:

JavaScript

This is referring to the builtin id function, which requires an argument because it returns the internal ID of an object in Python. It has nothing to do with database IDs, and doesn’t belong here at all. I can only guess that you were asked for a default when creating the migration and you just typed in id.

You should delete that default from the migration, but that may make it unable to execute. You could also try a default of 0, which makes sense there; but your actual models code shows that field as the primary key, so you presumably have another subsequent migration that changes the field again; and 0 wouldn’t work as a pk.

If you’re still in development and don’t have any data you need to keep, I would suggest deleting your database and migrations completely and starting again with makemigrations.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement