generate id if is null when build insert query + fixes