mirror of
https://github.com/django/django.git
synced 2025-06-08 04:59:13 +00:00
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.apps import apps
|
||||||
from django.conf import settings
|
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 import connections
|
||||||
from django.db.models import Manager
|
from django.db.models import Manager
|
||||||
from django.db.models.fields import AutoField
|
from django.db.models.fields import AutoField
|
||||||
@ -244,9 +244,8 @@ class Options(object):
|
|||||||
field.primary_key = True
|
field.primary_key = True
|
||||||
self.setup_pk(field)
|
self.setup_pk(field)
|
||||||
if not field.remote_field.parent_link:
|
if not field.remote_field.parent_link:
|
||||||
warnings.warn(
|
raise ImproperlyConfigured(
|
||||||
'Add parent_link=True to %s as an implicit link is '
|
'Add parent_link=True to %s.' % field,
|
||||||
'deprecated.' % field, RemovedInDjango20Warning
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
auto = AutoField(verbose_name='ID', primary_key=True, auto_created=True)
|
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.
|
* The ``javascript_catalog()`` and ``json_catalog()`` views are removed.
|
||||||
|
|
||||||
* ``django.contrib.gis.utils.precision_wkt()`` is 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
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.checks import Error
|
from django.core.checks import Error
|
||||||
from django.core.checks.model_checks import _check_lazy_references
|
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 import connections, models
|
||||||
from django.db.models.signals import post_init
|
from django.db.models.signals import post_init
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
@ -783,26 +783,14 @@ class OtherModelTests(SimpleTestCase):
|
|||||||
self.assertEqual(errors, expected)
|
self.assertEqual(errors, expected)
|
||||||
|
|
||||||
def test_missing_parent_link(self):
|
def test_missing_parent_link(self):
|
||||||
with warnings.catch_warnings(record=True) as warns:
|
msg = 'Add parent_link=True to invalid_models_tests.ParkingLot.parent.'
|
||||||
warnings.simplefilter('always')
|
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||||
|
|
||||||
class Place(models.Model):
|
class Place(models.Model):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class ParkingLot(Place):
|
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)
|
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):
|
def test_m2m_table_name_clash(self):
|
||||||
class Foo(models.Model):
|
class Foo(models.Model):
|
||||||
bar = models.ManyToManyField('Bar', db_table='myapp_bar')
|
bar = models.ManyToManyField('Bar', db_table='myapp_bar')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user