Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
fcc4e251
Kaydet (Commit)
fcc4e251
authored
May 23, 2018
tarafından
Jeff
Kaydeden (comit)
Tim Graham
Haz 15, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29000 -- Fixed RenameModel's renaming of a M2M column when run after RenameField.
Regression in
45ded053
.
üst
3eb91276
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
6 deletions
+35
-6
fields.py
django/db/migrations/operations/fields.py
+7
-6
test_operations.py
tests/migrations/test_operations.py
+28
-0
No files found.
django/db/migrations/operations/fields.py
Dosyayı görüntüle @
fcc4e251
...
@@ -271,15 +271,10 @@ class RenameField(FieldOperation):
...
@@ -271,15 +271,10 @@ class RenameField(FieldOperation):
# Rename the field
# Rename the field
fields
=
model_state
.
fields
fields
=
model_state
.
fields
found
=
False
found
=
False
delay
=
True
for
index
,
(
name
,
field
)
in
enumerate
(
fields
):
for
index
,
(
name
,
field
)
in
enumerate
(
fields
):
if
not
found
and
name
==
self
.
old_name
:
if
not
found
and
name
==
self
.
old_name
:
fields
[
index
]
=
(
self
.
new_name
,
field
)
fields
[
index
]
=
(
self
.
new_name
,
field
)
# Delay rendering of relationships if it's not a relational
# field and not referenced by a foreign key.
delay
=
(
not
field
.
is_relation
and
not
is_referenced_by_foreign_key
(
state
,
self
.
model_name_lower
,
field
,
self
.
name
)
)
found
=
True
found
=
True
# Fix from_fields to refer to the new field.
# Fix from_fields to refer to the new field.
from_fields
=
getattr
(
field
,
'from_fields'
,
None
)
from_fields
=
getattr
(
field
,
'from_fields'
,
None
)
...
@@ -288,6 +283,12 @@ class RenameField(FieldOperation):
...
@@ -288,6 +283,12 @@ class RenameField(FieldOperation):
self
.
new_name
if
from_field_name
==
self
.
old_name
else
from_field_name
self
.
new_name
if
from_field_name
==
self
.
old_name
else
from_field_name
for
from_field_name
in
from_fields
for
from_field_name
in
from_fields
])
])
# Delay rendering of relationships if it's not a relational
# field and not referenced by a foreign key.
delay
=
delay
and
(
not
field
.
is_relation
and
not
is_referenced_by_foreign_key
(
state
,
self
.
model_name_lower
,
field
,
self
.
name
)
)
if
not
found
:
if
not
found
:
raise
FieldDoesNotExist
(
raise
FieldDoesNotExist
(
"
%
s.
%
s has no field named '
%
s'"
%
(
app_label
,
self
.
model_name
,
self
.
old_name
)
"
%
s.
%
s has no field named '
%
s'"
%
(
app_label
,
self
.
model_name
,
self
.
old_name
)
...
...
tests/migrations/test_operations.py
Dosyayı görüntüle @
fcc4e251
...
@@ -802,6 +802,34 @@ class OperationTests(OperationTestBase):
...
@@ -802,6 +802,34 @@ class OperationTests(OperationTestBase):
self
.
assertEqual
(
PonyRider
.
objects
.
count
(),
2
)
self
.
assertEqual
(
PonyRider
.
objects
.
count
(),
2
)
self
.
assertEqual
(
pony
.
riders
.
count
(),
2
)
self
.
assertEqual
(
pony
.
riders
.
count
(),
2
)
def
test_rename_m2m_model_after_rename_field
(
self
):
"""RenameModel renames a many-to-many column after a RenameField."""
app_label
=
'test_rename_multiple'
project_state
=
self
.
apply_operations
(
app_label
,
ProjectState
(),
operations
=
[
migrations
.
CreateModel
(
'Pony'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
primary_key
=
True
)),
(
'name'
,
models
.
CharField
(
max_length
=
20
)),
]),
migrations
.
CreateModel
(
'Rider'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
primary_key
=
True
)),
(
'pony'
,
models
.
ForeignKey
(
'test_rename_multiple.Pony'
,
models
.
CASCADE
)),
]),
migrations
.
CreateModel
(
'PonyRider'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
primary_key
=
True
)),
(
'riders'
,
models
.
ManyToManyField
(
'Rider'
)),
]),
migrations
.
RenameField
(
model_name
=
'pony'
,
old_name
=
'name'
,
new_name
=
'fancy_name'
),
migrations
.
RenameModel
(
old_name
=
'Rider'
,
new_name
=
'Jockey'
),
],
atomic
=
connection
.
features
.
supports_atomic_references_rename
)
Pony
=
project_state
.
apps
.
get_model
(
app_label
,
'Pony'
)
Jockey
=
project_state
.
apps
.
get_model
(
app_label
,
'Jockey'
)
PonyRider
=
project_state
.
apps
.
get_model
(
app_label
,
'PonyRider'
)
# No "no such column" error means the column was renamed correctly.
pony
=
Pony
.
objects
.
create
(
fancy_name
=
'a good name'
)
jockey
=
Jockey
.
objects
.
create
(
pony
=
pony
)
ponyrider
=
PonyRider
.
objects
.
create
()
ponyrider
.
riders
.
add
(
jockey
)
def
test_add_field
(
self
):
def
test_add_field
(
self
):
"""
"""
Tests the AddField operation.
Tests the AddField operation.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment