Corrected nextval() for sequences

This prevents duplicate key errors.