1
0
mirror of https://github.com/django/django.git synced 2025-10-27 23:56:08 +00:00

[1.11.x] Fixed #28350 -- Fixed UnboundLocalError crash in RenameField with nonexistent field.

Thanks Tim for the review.

Backport of 5cbcb36839 from master
This commit is contained in:
Simon Charette
2017-06-30 08:35:58 -04:00
parent a6756195c1
commit c1621d8008
3 changed files with 24 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ from __future__ import unicode_literals
import unittest
from django.core.exceptions import FieldDoesNotExist
from django.db import connection, migrations, models, transaction
from django.db.migrations.migration import Migration
from django.db.migrations.operations import CreateModel
@@ -1370,6 +1371,12 @@ class OperationTests(OperationTestBase):
self.assertEqual(definition[1], [])
self.assertEqual(definition[2], {'model_name': "Pony", 'old_name': "pink", 'new_name': "blue"})
def test_rename_missing_field(self):
state = ProjectState()
state.add_model(ModelState('app', 'model', []))
with self.assertRaisesMessage(FieldDoesNotExist, "app.model has no field named 'field'"):
migrations.RenameField('model', 'field', 'new_field').state_forwards('app', state)
def test_alter_unique_together(self):
"""
Tests the AlterUniqueTogether operation.