title: MYSQL foreign key constraint check in transaction?
body: <p>I have following error while executing following transaction.
  <em>Error : #1452 - Cannot add or update a child row: a foreign key constraint fails (<code>crowdsource</code>.<code>posts_category</code>, CONSTRAINT <code>FK_posts_pcategory</code> FOREIGN KEY (<code>post_id</code>) REFERENCES <code>posts</code> (<code>post_id</code>) ON DELETE NO ACTION ON UPDATE CASCADE)</em> </p>
  
  <p>Transaction:</p>
  
  <p><strong>start transaction;
  select @id := max(post_id) from <code>posts</code>;
  set @id = @id+1;
  INSERT INTO <code>posts</code>(<code>post_id</code>,<code>content</code>, <code>url</code>, <code>post_time</code>) VALUES (@id,'hello','',now());
  SELECT * from posts;
  INSERT INTO <code>posts_category</code>(<code>post_id</code>, <code>category_id</code>) VALUES (@id,1001),(@id,1002);
  commit;</strong></p>
  
  <p>My database schema has FK between <code>posts</code> and <code>posts_category</code> tables ('post_id')</p>
  
  <p>Do I need to keep SET FOREIGN_KEY_CHECKS = 0; before inserting into post_category table?</p>