Unknown column 'type' in 'where clause'