We found that the absence of NIPA2 in osteoblasts leads to deficiency of intracellular magnesium under type 2 diabetes environment. Here, NIPA2 is linked to type 2 diabetes mellitus.