Skip to content
Advertisement

The INSERT statement conflicted with the FOREIGN KEY constraint “FK__Messages__Email__3D9E16F4”

Maybe someone can tell me why this is happening. I wrote this stored procedure:

CREATE PROCEDURE Newmessages 
    @Message_id VARCHAR(20)
    ,@First_name VARCHAR(20)
    ,@Last_name VARCHAR(20)
    ,@Email VARCHAR(20)
    ,@Phone VARCHAR(20)
    ,@Postal_code VARCHAR(20)
    ,@Notification_1 BIT
    ,@Notification_2 BIT
    ,@Own_Pets BIT
    ,@Organization_Id VARCHAR(20)
    ,@Animal_Id VARCHAR(20)
AS
    INSERT INTO [dbo].[Messages]
    VALUES (@Message_id, @First_name, @Last_name, @Email, @Phone,
            @Postal_code, @Notification_1, @Notification_2, @Own_Pets,
            @Organization_Id, @Animal_Id)

Now I’m trying to check it by inserting:

exec Newmessages '64654', 'Kelli', 'Adkins', 'acprthvs.bpuzcnt@gmail.com', '478-6273327', 'SR5 2QF', 'False', 'False', 'False', '91839', '40550'

and I get:

Msg 547, Level 16, State 0, Procedure Newmessages, Line 4 [Batch Start Line 0] > The INSERT statement conflicted with the FOREIGN KEY constraint “FK__Messages__Email__3D9E16F4”. The conflict occurred in database “Petfinder”, table “dbo.Users”, column ‘Email’.

Thing is, I checked and I do have the email I’m trying to insert in the Users table (which is the error).

Here I checked that it does exist in dbo.Users:

enter image description here

Does anyone know why this is still happening?

Advertisement

Answer

The email address you’re trying to insert is acprthvs.bpuzcnt@gma, which doesn’t exist in your table.

CREATE PROCEDURE Newmessages 
    ...
    ,@Email VARCHAR(20)
    ...

The email address you’d like to enter is 26 characters long.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement