A primary key value must exist first before it can be used as foreign key in another table. For example:
To insert students into student table whose teacherid is "james123", you have to ensure that this "james123" already exists in the teacher table otherwise you have to insert this teacher first, e.g.
INSERT INTO teacher (teacherid, teachername) VALUES ('james123','James')
After inserting the teacher then can you insert new students whose teacher is 'james123', e.g.
INSERT INTO student (studentid, studentname, teacherid) VALUES ('student1','name of student1','james123')
For block insert, you should follow the solution by Christian Graus.