Open onyekaa opened 6 years ago
Update: Looks like I haven't completely fixed this. It still fails when the field is empty. I don't know why it thinks "" is a value, and as a variable it keeps returning true. Maybe it's because my JS isn't fantastic, but the only way I could catch that was to literally check for if (value != "")
. It feels hacky though.
Okay so this drove me a little crazy for a couple of hours. I added a ManyToMany field in my Image Model, where a user could select multiple users. The field is not required. However whenever I tried to leave the field empty and upload I kept getting
"" is not a valid value for a primary key.
Some experimenting showed that if I selected ONE item, it would upload fine, but then if I tried to select 2+ items, I'd get
"2,3" is not a valid value for a primary key.
Long story short, the error was from the
start_upload
function, when the field values are attached tonew FormData()
. Apparently FormaData converts the array of values sent by theselect multiple
field to a string-like value.To circumvent this I changed the code to check for arrays.