mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #11702: Catch to_field specifying a non-unique target in validation. Thanks marcosmoyano.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12756 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
d312fa2a61
commit
079457ff01
2 changed files with 27 additions and 1 deletions
|
@ -180,7 +180,27 @@ class AbstractRelationModel(models.Model):
|
|||
|
||||
class UniqueM2M(models.Model):
|
||||
""" Model to test for unique ManyToManyFields, which are invalid. """
|
||||
unique_people = models.ManyToManyField( Person, unique=True )
|
||||
unique_people = models.ManyToManyField(Person, unique=True)
|
||||
|
||||
class NonUniqueFKTarget1(models.Model):
|
||||
""" Model to test for non-unique FK target in yet-to-be-defined model: expect an error """
|
||||
tgt = models.ForeignKey('FKTarget', to_field='bad')
|
||||
|
||||
class UniqueFKTarget1(models.Model):
|
||||
""" Model to test for unique FK target in yet-to-be-defined model: expect no error """
|
||||
tgt = models.ForeignKey('FKTarget', to_field='good')
|
||||
|
||||
class FKTarget(models.Model):
|
||||
bad = models.IntegerField()
|
||||
good = models.IntegerField(unique=True)
|
||||
|
||||
class NonUniqueFKTarget2(models.Model):
|
||||
""" Model to test for non-unique FK target in previously seen model: expect an error """
|
||||
tgt = models.ForeignKey(FKTarget, to_field='bad')
|
||||
|
||||
class UniqueFKTarget2(models.Model):
|
||||
""" Model to test for unique FK target in previously seen model: expect no error """
|
||||
tgt = models.ForeignKey(FKTarget, to_field='good')
|
||||
|
||||
|
||||
model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute.
|
||||
|
@ -279,4 +299,6 @@ invalid_models.personselfrefm2mexplicit: Many-to-many fields with intermediate t
|
|||
invalid_models.abstractrelationmodel: 'fk1' has a relation with model AbstractModel, which has either not been installed or is abstract.
|
||||
invalid_models.abstractrelationmodel: 'fk2' has an m2m relation with model AbstractModel, which has either not been installed or is abstract.
|
||||
invalid_models.uniquem2m: ManyToManyFields cannot be unique. Remove the unique argument on 'unique_people'.
|
||||
invalid_models.nonuniquefktarget1: Field 'bad' under model 'FKTarget' must have a unique=True constraint.
|
||||
invalid_models.nonuniquefktarget2: Field 'bad' under model 'FKTarget' must have a unique=True constraint.
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue