[Answer]-Django Admin error Truncated incorrect DOUBLE value:" "

1👍

Drop your table (or database) and then run syncdb again. You should do this after you make changes in your models.

The error is because your database is storing the column Publisher as a DOUBLE and you are trying to insert a string Penguin Books in it.

Either you have made changes to your model and didn’t drop and recreate the tables (by running syncdb), or you are doing something like this:

book = Book()
book.title = 'Some Title'
book.publisher = 'Penguin Books'
book.save()

The problem with the above is that publisher is a foreign key, so you need to add a reference to the Publisher model, so something like this:

 publisher = Publisher()
 publisher.name = 'Penguin Books'
 publisher.save()

 book = Book()
 book.title = 'Some Title'
 book.publisher = publisher # here you are assigning the "Publisher" object
 book.save()

0👍

The problem is quite simple because you did not register those names in the fields parameter.

This is how it should look like:

class BookAdmin(admin.ModelAdmin):
    fields = ('title', 'publisher')
    list_display = ('title', 'publisher')

admin.site.register(Book, BookAdmin)

Leave a comment