Search code examples
htmldatabaseresthttphttpresponse

Which HTTP response status code to use when inserting an element which references a non existing element into a database?


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.


Solution

  • 404 Not Found would be a better option. With an error message "country not found".