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)
- [Answer]-Building layers with geodjango and google maps by social network users
- [Answer]-Django: how to upload file
Source:stackexchange.com