We explore the constraints imposed by the cancellation of triangle anomalies on models in which the flavour anomalies reported by LHCb and other experiments are due to an extra U(1) gauge boson Z . We assume universal and rational U(1) charges for the first two generations of lefthanded quarks and of right-handed up-type quarks but allow different charges for their third-generation counterparts. If the right-handed charges vanish, cancellation of the triangle anomalies requires all the quark U(1) charges to vanish, if there are either no exotic fermions or there is only one Standard Model singlet dark matter (DM) fermion. There are non-trivial anomaly-free models with more than one such 'dark' fermion, or with a single DM fermion if right-handed up-type quarks have non-zero U(1) charges. In some of the latter models the U(1) couplings of the first-and secondgeneration quarks all vanish, weakening the LHC Z constraint, and in some other models the DM particle has purely axial couplings, weakening the direct DM scattering constraint. We also consider models in which anomalies are cancelled via extra vector-like leptons, showing how the prospective LHC Z constraint may be weakened because the Z → μ + μ − branching ratio is suppressed relative to other decay modes.