mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Teach "django-admin.py validate" to forbid nullable primary keys.
Fixes #15884, with thanks to JustinTArthur and Julie Pichon. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16678 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -220,7 +220,8 @@ class InvalidSetDefault(models.Model):
|
||||
fk = models.ForeignKey('self', on_delete=models.SET_DEFAULT)
|
||||
|
||||
class UnicodeForeignKeys(models.Model):
|
||||
"""Foreign keys which can translate to ascii should be OK, but fail if they're not."""
|
||||
"""Foreign keys which can translate to ascii should be OK, but fail if
|
||||
they're not."""
|
||||
good = models.ForeignKey(u'FKTarget')
|
||||
also_good = models.ManyToManyField(u'FKTarget', related_name='unicode2')
|
||||
|
||||
@@ -228,6 +229,9 @@ class UnicodeForeignKeys(models.Model):
|
||||
# when adding the errors in core/management/validation.py
|
||||
#bad = models.ForeignKey(u'★')
|
||||
|
||||
class PrimaryKeyNull(models.Model):
|
||||
my_pk_field = models.IntegerField(primary_key=True, null=True)
|
||||
|
||||
|
||||
model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute that is a positive integer.
|
||||
invalid_models.fielderrors: "charfield2": CharFields require a "max_length" attribute that is a positive integer.
|
||||
@@ -338,4 +342,5 @@ invalid_models.nonuniquefktarget2: Field 'bad' under model 'FKTarget' must have
|
||||
invalid_models.nonexistingorderingwithsingleunderscore: "ordering" refers to "does_not_exist", a field that doesn't exist.
|
||||
invalid_models.invalidsetnull: 'fk' specifies on_delete=SET_NULL, but cannot be null.
|
||||
invalid_models.invalidsetdefault: 'fk' specifies on_delete=SET_DEFAULT, but has no default value.
|
||||
invalid_models.primarykeynull: "my_pk_field": Primary key fields cannot have null=True.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user