Ticket #11702: new_patch.patch
File new_patch.patch, 2.7 KB (added by , 15 years ago) |
---|
-
django/core/management/validation.py
79 79 # so skip the next section 80 80 if isinstance(f.rel.to, (str, unicode)): 81 81 continue 82 # Let's make sure we have unique=True if to_field is set in a ForeignKey# 83 if f.rel.field_name: 84 to_field = f.rel.field_name or (r.rel.to._meta.pk and f.rel.to._meta.pk.name) 85 if to_field: 86 try: 87 assert f.rel.to._meta.get_field(to_field).unique, \ 88 "Field %s under model %s must have a unique=True constraint." % (to_field, f.rel.to.__name__) 89 except: 90 e.add(opts, "Field '%s' under model '%s' must have a unique=True constraint." % (to_field, f.rel.to.__name__)) 82 91 83 92 rel_opts = f.rel.to._meta 84 93 rel_name = RelatedObject(f.rel.to, cls, f).get_accessor_name() -
tests/modeltests/invalid_models/models.py
182 182 """ Model to test for unique ManyToManyFields, which are invalid. """ 183 183 unique_people = models.ManyToManyField( Person, unique=True ) 184 184 185 class Author(models.Model): 186 code = models.CharField(max_length=10, db_index=True) 187 first_name = models.CharField(max_length=30) 188 last_name = models.CharField(max_length=40) 185 189 190 class Book(models.Model): 191 """This model should fail""" 192 title = models.CharField(max_length=100) 193 author = models.ForeignKey(Author, to_field='code') 194 186 195 model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute. 187 196 invalid_models.fielderrors: "decimalfield": DecimalFields require a "decimal_places" attribute. 188 197 invalid_models.fielderrors: "decimalfield": DecimalFields require a "max_digits" attribute. … … 279 288 invalid_models.abstractrelationmodel: 'fk1' has a relation with model AbstractModel, which has either not been installed or is abstract. 280 289 invalid_models.abstractrelationmodel: 'fk2' has an m2m relation with model AbstractModel, which has either not been installed or is abstract. 281 290 invalid_models.uniquem2m: ManyToManyFields cannot be unique. Remove the unique argument on 'unique_people'. 291 invalid_models.book: Field 'code' under model 'Author' must have a unique=True constraint. 282 292 """