[Fixed]-Django Admin cannot render tables without Primary Key

1👍

If you’ve made changes to the model in question, you might need to migrate. In your project’s root directory (or wherever the manage.py file is) type

$ python manage.py makemigrations

Then type

$ python manage.py migrate

It could be that you added a model field to the model, but it’s not in the database yet, so you get this error when you try to edit it in admin.

UPDATE

Based on this question and this one, it sounds like Django tried to auto-add an id column since you didn’t define a primary key on your model. That id may not have propagated to the database. Therefore try

$ python manage.py dbshell

Now you can add the column straight to the database table

mysql> ALTER TABLE your_table_name ADD id integer AUTO_INCREMENT NOT NULL PRIMARY KEY FIRST;
mysql> exit;

Then try reloading your admin page…

Leave a comment