I have a table with cities that has a foreign key constraint on another table, countries. What status code should I return if the client sends a POST request with a city that references a country that doesn't exist in the countries table? I was thinking 400 BAD REQUEST
, but this seems to be related only to the syntax of the request.
CodePudding user response:
404 Not Found would be a better option. With an error message "country not found".
CodePudding user response:
You could use HTTP 422/Unprocessable Entity
The request was well-formed but was unable to be followed due to semantic errors.
The 400/Bad Request
is too vague, but 404/Not found
could also fit perfectly in your case.