I have a .net core web api deployed on azure with mssql database which is also deployed on azure. I try to do a post request from postman and it's successful but when i try to do it inside my react app using axios i get 500 error which has this error message:
Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details.
---> Microsoft.Data.SqlClient.SqlException (0x80131904): The INSERT statement conflicted with the FOREIGN KEY constraint "FK_TextWidgets_Users_UserId". The conflict occurred in database "SchoolProjectDB", table "dbo.Users", column 'Id'. The statement has been terminated.
Here is my client side axios code:
var textWidgetData = {
"text": text,
"userId": 1,
}
const CreateHandler = () => {
console.log(textWidgetData);
axios.post("/TextWidget", {textWidgetData}).then(res => {
console.log(res);
console.log(res.data);
})
}
i solved it problem was in {textWidgetData} part. i replaced it with textWidgetData. And it worked. The 500 error message about foreign key fooled me.
User contributions licensed under CC BY-SA 3.0