Why I Am Getting An "(admin.e003) The Value Of 'raw_id_fields[n]' Must Be A Foreignkey Or Manytomanyfield." Error In Django App?
I want to make a schema migration, just add 1 field to Model and to ModelAdmin. class MyModel(models.Model): some_field = models.ForeignKey(SomeModel) my_new_field = models
Solution 1:
From the docs:
raw_id_fields is a list of fields you would like to change into an Input widget for either a ForeignKey or ManyToManyField
my_new_field
is a CharField
and its name therefore an invalid element of raw_id_fields
. This class attribute is meant for relation fields where you don't want the overhead of generating the default select dropdown from a queryset but want to use a common input to enter raw ids. Just add your field to fields
instead:
classMyModelAdmin(admin.ModelAdmin):
# ...
fields = ['some_field', 'my_new_field']
raw_id_fields = ['some_field']
Post a Comment for "Why I Am Getting An "(admin.e003) The Value Of 'raw_id_fields[n]' Must Be A Foreignkey Or Manytomanyfield." Error In Django App?"