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
107c9f54
Kaydet (Commit)
107c9f54
authored
Mar 11, 2014
tarafından
Chris Beaven
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix AlterField migrations that are related to a RenameModel migration
üst
40f6ca54
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
5 deletions
+53
-5
fields.py
django/db/migrations/operations/fields.py
+12
-5
test_operations.py
tests/migrations/test_operations.py
+41
-0
No files found.
django/db/migrations/operations/fields.py
Dosyayı görüntüle @
107c9f54
from
django.db
import
router
from
django.db.models.fields
import
NOT_PROVIDED
from
django.utils
import
six
from
.base
import
Operation
...
...
@@ -116,11 +117,17 @@ class AlterField(Operation):
from_model
=
from_state
.
render
()
.
get_model
(
app_label
,
self
.
model_name
)
to_model
=
to_state
.
render
()
.
get_model
(
app_label
,
self
.
model_name
)
if
router
.
allow_migrate
(
schema_editor
.
connection
.
alias
,
to_model
):
schema_editor
.
alter_field
(
from_model
,
from_model
.
_meta
.
get_field_by_name
(
self
.
name
)[
0
],
to_model
.
_meta
.
get_field_by_name
(
self
.
name
)[
0
],
)
from_field
=
from_model
.
_meta
.
get_field_by_name
(
self
.
name
)[
0
]
to_field
=
to_model
.
_meta
.
get_field_by_name
(
self
.
name
)[
0
]
# If the field is a relatedfield with an unresolved rel.to, just
# set it equal to the other field side. Bandaid fix for AlterField
# migrations that are part of a RenameModel change.
if
from_field
.
rel
and
from_field
.
rel
.
to
:
if
isinstance
(
from_field
.
rel
.
to
,
six
.
string_types
):
from_field
.
rel
.
to
=
to_field
.
rel
.
to
elif
isinstance
(
to_field
.
rel
.
to
,
six
.
string_types
):
to_field
.
rel
.
to
=
from_field
.
rel
.
to
schema_editor
.
alter_field
(
from_model
,
from_field
,
to_field
)
def
database_backwards
(
self
,
app_label
,
schema_editor
,
from_state
,
to_state
):
self
.
database_forwards
(
app_label
,
schema_editor
,
from_state
,
to_state
)
...
...
tests/migrations/test_operations.py
Dosyayı görüntüle @
107c9f54
...
...
@@ -226,6 +226,47 @@ class OperationTests(MigrationTestBase):
self
.
assertTableExists
(
"test_dlmo_pony"
)
self
.
assertTableNotExists
(
"test_rnmo_horse"
)
def
test_rename_model_with_related
(
self
):
"""
Tests the real-world combo of a RenameModel operation with AlterField
for a related field.
"""
project_state
=
self
.
set_up_test_model
(
"test_rnmowr"
,
related_model
=
True
)
# Test the state alterations
model_operation
=
migrations
.
RenameModel
(
"Pony"
,
"Horse"
)
new_state
=
project_state
.
clone
()
model_operation
.
state_forwards
(
"test_rnmowr"
,
new_state
)
self
.
assertNotIn
((
"test_rnmowr"
,
"pony"
),
new_state
.
models
)
self
.
assertIn
((
"test_rnmowr"
,
"horse"
),
new_state
.
models
)
self
.
assertEqual
(
"Pony"
,
project_state
.
render
()
.
get_model
(
"test_rnmowr"
,
"rider"
)
.
_meta
.
get_field_by_name
(
"pony"
)[
0
]
.
rel
.
to
.
_meta
.
object_name
)
field_operation
=
migrations
.
AlterField
(
"Rider"
,
"pony"
,
models
.
ForeignKey
(
"Horse"
))
field_operation
.
state_forwards
(
"test_rnmowr"
,
new_state
)
self
.
assertEqual
(
"Horse"
,
new_state
.
render
()
.
get_model
(
"test_rnmowr"
,
"rider"
)
.
_meta
.
get_field_by_name
(
"pony"
)[
0
]
.
rel
.
to
.
_meta
.
object_name
)
# Test the database alterations
self
.
assertTableExists
(
"test_rnmowr_pony"
)
self
.
assertTableNotExists
(
"test_rnmowr_horse"
)
with
connection
.
schema_editor
()
as
editor
:
model_operation
.
database_forwards
(
"test_rnmowr"
,
editor
,
project_state
,
new_state
)
field_operation
.
database_forwards
(
"test_rnmowr"
,
editor
,
project_state
,
new_state
)
self
.
assertTableNotExists
(
"test_rnmowr_pony"
)
self
.
assertTableExists
(
"test_rnmowr_horse"
)
# And test reversal
with
connection
.
schema_editor
()
as
editor
:
field_operation
.
database_backwards
(
"test_rnmowr"
,
editor
,
new_state
,
project_state
)
model_operation
.
database_backwards
(
"test_rnmowr"
,
editor
,
new_state
,
project_state
)
self
.
assertTableExists
(
"test_rnmowr_pony"
)
self
.
assertTableNotExists
(
"test_rnmowr_horse"
)
def
test_add_field
(
self
):
"""
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