Refs #26320 -- Removed implicit OneToOnField parent_link per deprecation timeline.
This commit is contained in:
parent
1691782652
commit
9d0e8c1e7f
|
@ -8,7 +8,7 @@ from itertools import chain
|
|||
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import FieldDoesNotExist
|
||||
from django.core.exceptions import FieldDoesNotExist, ImproperlyConfigured
|
||||
from django.db import connections
|
||||
from django.db.models import Manager
|
||||
from django.db.models.fields import AutoField
|
||||
|
@ -244,9 +244,8 @@ class Options(object):
|
|||
field.primary_key = True
|
||||
self.setup_pk(field)
|
||||
if not field.remote_field.parent_link:
|
||||
warnings.warn(
|
||||
'Add parent_link=True to %s as an implicit link is '
|
||||
'deprecated.' % field, RemovedInDjango20Warning
|
||||
raise ImproperlyConfigured(
|
||||
'Add parent_link=True to %s.' % field,
|
||||
)
|
||||
else:
|
||||
auto = AutoField(verbose_name='ID', primary_key=True, auto_created=True)
|
||||
|
|
|
@ -370,3 +370,6 @@ these features.
|
|||
* The ``javascript_catalog()`` and ``json_catalog()`` views are removed.
|
||||
|
||||
* ``django.contrib.gis.utils.precision_wkt()`` is removed.
|
||||
|
||||
* In multi-table inheritance, implicit promotion of a ``OneToOneField`` to a
|
||||
``parent_link`` is removed.
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.checks import Error
|
||||
from django.core.checks.model_checks import _check_lazy_references
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db import connections, models
|
||||
from django.db.models.signals import post_init
|
||||
from django.test import SimpleTestCase
|
||||
|
@ -783,26 +783,14 @@ class OtherModelTests(SimpleTestCase):
|
|||
self.assertEqual(errors, expected)
|
||||
|
||||
def test_missing_parent_link(self):
|
||||
with warnings.catch_warnings(record=True) as warns:
|
||||
warnings.simplefilter('always')
|
||||
|
||||
msg = 'Add parent_link=True to invalid_models_tests.ParkingLot.parent.'
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||
class Place(models.Model):
|
||||
pass
|
||||
|
||||
class ParkingLot(Place):
|
||||
# In lieu of any other connector, an existing OneToOneField will be
|
||||
# promoted to the primary key.
|
||||
parent = models.OneToOneField(Place, models.CASCADE)
|
||||
|
||||
self.assertEqual(len(warns), 1)
|
||||
msg = str(warns[0].message)
|
||||
self.assertEqual(
|
||||
msg,
|
||||
'Add parent_link=True to invalid_models_tests.ParkingLot.parent '
|
||||
'as an implicit link is deprecated.'
|
||||
)
|
||||
self.assertEqual(ParkingLot._meta.pk.name, 'parent')
|
||||
|
||||
def test_m2m_table_name_clash(self):
|
||||
class Foo(models.Model):
|
||||
bar = models.ManyToManyField('Bar', db_table='myapp_bar')
|
||||
|
|
Loading…
Reference in New Issue