.net core api returns 500 when i make a post request from axios post

0

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);
        })
    } 
sql-server
reactjs
asp.net-core
axios
asp.net-core-webapi
asked on Stack Overflow Dec 25, 2019 by kerems • edited Dec 26, 2019 by Roman Marusyk

1 Answer

0

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.

answered on Stack Overflow Dec 25, 2019 by kerems

User contributions licensed under CC BY-SA 3.0