diff --git a/django/db/models/options.py b/django/db/models/options.py index c4652870e0..8f6e2bd424 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -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) diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt index 9999e0ae18..c8aaab3e71 100644 --- a/docs/releases/2.0.txt +++ b/docs/releases/2.0.txt @@ -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. diff --git a/tests/invalid_models_tests/test_models.py b/tests/invalid_models_tests/test_models.py index 78f2164ed5..662035af75 100644 --- a/tests/invalid_models_tests/test_models.py +++ b/tests/invalid_models_tests/test_models.py @@ -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')