title: The INSERT statement conflicted with the FOREIGN KEY constraint"
body: <p>I'm trying to insert data into my SQL Server 2014 build and I keep getting this error. I tried searching all over the internet and at my whits end, I sort of get what people were saying but still having difficulty understanding what's wrong with my particular code.</p>
  
  <p>All tables are empty without data. I cannot add data once the foreign keys are set. I read that both tables must be populated for this to work but how does that happen when I can't add anything? If I add data before the foreign key, then I'm unable to add foreign keys. Please help!</p>
  
  <p>When trying to insert data into Gym row using the INSERT INTO I get this error:</p>
  
  <blockquote>
    <p>The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Gym__staffNo". The conflict occurred in database "FitnessApp", table "dbo.Staff", column 'staffNo'.</p>
  </blockquote>
  
  <p>This also happens when trying to add data into the <code>Equipment</code> or <code>Staff</code> tables as well.</p>
  
  <p>See code here:</p>
  
  <p>Schema:</p>
  
  <pre><code>CREATE TABLE Gym
  (
  gymNo int NOT NULL IDENTITY(1,1),
  staffNo int NOT NULL,
  streetAddress varchar(100) NOT NULL,
  streetAddress2 varchar(100) NULL,
  city varchar(50) NOT NULL,
  state char(2) NOT NULL,
  zip char(5) NOT NULL,
  phone char(10) NOT NULL
  ) ON [fitnessPlusGroup1];
  
  CREATE TABLE Staff
  (
  staffNo int NOT NULL IDENTITY(1,1),
  gymNo int NOT NULL,
  position varchar(50) NOT NULL,
  firstName varchar(50) NOT NULL,
  lastName varchar(50) NOT NULL,
  streetAddress varchar(100) NOT NULL,
  streetAddress2 varchar(100) NULL,
  city varchar(50) NOT NULL,
  state char(2) NOT NULL,
  zip char(5) NOT NULL,
  phone char(10) NOT NULL,
  hireDate date NOT NULL
  ) ON [fitnessPlusGroup1];
  
  CREATE TABLE Member
  (
  memberNo int NOT NULL IDENTITY(1,1),
  gymNo int NOT NULL,
  firstName varchar(30) NOT NULL,
  lastName varchar(30) NOT NULL,
  streetAddress varchar(100) NOT NULL,
  streetAddress2 varchar(100) NULL,
  city varchar(50) NOT NULL,
  state char(2) NOT NULL,
  zip char(5) NOT NULL,
  phone char(10) NOT NULL,
  memberSince date NOT NULL,
  scheduleID int NULL
  ) ON [fitnessPlusGroup1];
  
  CREATE TABLE Schedule
  (
  scheduleID int NOT NULL IDENTITY(1,1),
  staffNo int NOT NULL,
  trainDate date NOT NULL,
  trainTime time(0) NOT NULL
  ) ON [fitnessPlusGroup1];
  
  CREATE TABLE Equipment
  (
  equipNo int NOT NULL IDENTITY(1,1),
  gymNo int NOT NULL,
  staffNo int NOT NULL,
  name varchar(50) NOT NULL,
  quantity int NOT NULL
  ) ON [fitnessPlusGroup1];
  </code></pre>
  
  <p>Foreign key relationships setup:</p>
  
  <pre><code>ALTER TABLE Gym
  ADD FOREIGN KEY (staffNo) REFERENCES Staff(staffNo);
  
  ALTER TABLE Staff
  ADD FOREIGN KEY (gymNo) REFERENCES Gym(gymNo); 
  
  ALTER TABLE Member
  ADD FOREIGN KEY (gymNo) REFERENCES Gym(gymNo);
  
  ALTER TABLE Member
  ADD FOREIGN KEY (scheduleID) REFERENCES Schedule(scheduleID);
  
  ALTER TABLE Schedule
  ADD FOREIGN KEY (staffNo) REFERENCES Staff(staffNo);
  
  ALTER TABLE Equipment
  ADD FOREIGN KEY (gymNo) REFERENCES Gym(gymNo);
  
  ALTER TABLE Equipment
  ADD FOREIGN KEY (staffNo) REFERENCES Staff(staffNo);
  </code></pre>
  
  <p>The insert commands that give errors:</p>
  
  <pre><code>INSERT INTO Gym(staffNo, streetAddress, streetAddress2, city, state, zip, phone) 
  VALUES (1, '7300 W Greens Rd', NULL, 'Houston', 'TX', '77064', '2818946151');
  </code></pre>
  
  <p>Any help would be much appreciated sorry if this seems like a bit much and I hope I provided all the info I could..</p>