Altcoin creation from bitcoin ReadBlockFromDisk: Errors in block header at CBlockDiskPos I am trying to create a altcoin using bitcoin source code.

i have changed the pszTimestamp, port number, magic number. I have cleared the DNS seeds and removed checkpoints for now.
Then I printed the following values using printf and updated the new values:
genesis.hashMerkleRoot and genesis.hashMerkleRoot

In the log file I see this error:


  2017-10-04 18:32:29 ERROR: ReadBlockFromDisk: Errors in block header at 
  CBlockDiskPos(nFile=0, nPos=8) 2017-10-04 18:32:29 *** Failed to read
  block 2017-10-04 18:32:29 Error: Error: A fatal internal error
  occurred, see debug.log for details


I tried to debug the code and i see that this is where it fails in pow.cpp :

 bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&amp; params) {
      bool fNegative;
      bool fOverflow;
      arith_uint256 bnTarget;

      bnTarget.SetCompact(nBits, &amp;fNegative, &amp;fOverflow);

      // Check range
      if (fNegative || bnTarget == 0 || fOverflow || bnTarget &gt; UintToArith256(params.powLimit))
      {
          LogPrintf("\ncase 1\n");
          return false;
      }
      // Check proof of work matches claimed amount
      if (UintToArith256(hash) &gt; bnTarget)
      {
          //LogPrintf(bnTarget);
          LogPrintf("\ncase 2\n");
          return false;
      }
      return true;
 }


It prints case 2. What does this mean? What am I missing?
instead of using merkel hash from the code run i used a genesis block generator to generate the hash,nounce. it took an hour to get the values using this code:

https://github.com/Gnaf/GenesisBlockZero

then i used the values from this and it worked.