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
0891503f
Kaydet (Commit)
0891503f
authored
Agu 17, 2017
tarafından
Jeremy Satterfield
Kaydeden (comit)
Tim Graham
Eyl 04, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28493 -- Made migrations autodetector find dependencies for model renaming.
üst
3f2b1d92
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
1 deletion
+38
-1
autodetector.py
django/db/migrations/autodetector.py
+7
-1
test_autodetector.py
tests/migrations/test_autodetector.py
+31
-0
No files found.
django/db/migrations/autodetector.py
Dosyayı görüntüle @
0891503f
...
@@ -468,12 +468,18 @@ class MigrationAutodetector:
...
@@ -468,12 +468,18 @@ class MigrationAutodetector:
rem_model_fields_def
=
self
.
only_relation_agnostic_fields
(
rem_model_state
.
fields
)
rem_model_fields_def
=
self
.
only_relation_agnostic_fields
(
rem_model_state
.
fields
)
if
model_fields_def
==
rem_model_fields_def
:
if
model_fields_def
==
rem_model_fields_def
:
if
self
.
questioner
.
ask_rename_model
(
rem_model_state
,
model_state
):
if
self
.
questioner
.
ask_rename_model
(
rem_model_state
,
model_state
):
model_opts
=
self
.
new_apps
.
get_model
(
app_label
,
model_name
)
.
_meta
dependencies
=
[]
for
field
in
model_opts
.
get_fields
():
if
field
.
is_relation
:
dependencies
.
extend
(
self
.
_get_dependencies_for_foreign_key
(
field
))
self
.
add_operation
(
self
.
add_operation
(
app_label
,
app_label
,
operations
.
RenameModel
(
operations
.
RenameModel
(
old_name
=
rem_model_state
.
name
,
old_name
=
rem_model_state
.
name
,
new_name
=
model_state
.
name
,
new_name
=
model_state
.
name
,
)
),
dependencies
=
dependencies
,
)
)
self
.
renamed_models
[
app_label
,
model_name
]
=
rem_model_name
self
.
renamed_models
[
app_label
,
model_name
]
=
rem_model_name
renamed_models_rel_key
=
'
%
s.
%
s'
%
(
rem_model_state
.
app_label
,
rem_model_state
.
name
)
renamed_models_rel_key
=
'
%
s.
%
s'
%
(
rem_model_state
.
app_label
,
rem_model_state
.
name
)
...
...
tests/migrations/test_autodetector.py
Dosyayı görüntüle @
0891503f
...
@@ -901,6 +901,37 @@ class AutodetectorTests(TestCase):
...
@@ -901,6 +901,37 @@ class AutodetectorTests(TestCase):
self
.
assertOperationTypes
(
changes
,
"testapp"
,
0
,
[
"RenameModel"
])
self
.
assertOperationTypes
(
changes
,
"testapp"
,
0
,
[
"RenameModel"
])
self
.
assertOperationAttributes
(
changes
,
"testapp"
,
0
,
0
,
old_name
=
"EntityB"
,
new_name
=
"RenamedEntityB"
)
self
.
assertOperationAttributes
(
changes
,
"testapp"
,
0
,
0
,
old_name
=
"EntityB"
,
new_name
=
"RenamedEntityB"
)
def
test_rename_model_reverse_relation_dependencies
(
self
):
"""
The migration to rename a model pointed to by a foreign key in another
app must run after the other app's migration that adds the foreign key
with model's original name. Therefore, the renaming migration has a
dependency on that other migration.
"""
before
=
[
ModelState
(
'testapp'
,
'EntityA'
,
[
(
'id'
,
models
.
AutoField
(
primary_key
=
True
)),
]),
ModelState
(
'otherapp'
,
'EntityB'
,
[
(
'id'
,
models
.
AutoField
(
primary_key
=
True
)),
(
'entity_a'
,
models
.
ForeignKey
(
'testapp.EntityA'
,
models
.
CASCADE
)),
]),
]
after
=
[
ModelState
(
'testapp'
,
'RenamedEntityA'
,
[
(
'id'
,
models
.
AutoField
(
primary_key
=
True
)),
]),
ModelState
(
'otherapp'
,
'EntityB'
,
[
(
'id'
,
models
.
AutoField
(
primary_key
=
True
)),
(
'entity_a'
,
models
.
ForeignKey
(
'testapp.RenamedEntityA'
,
models
.
CASCADE
)),
]),
]
changes
=
self
.
get_changes
(
before
,
after
,
MigrationQuestioner
({
'ask_rename_model'
:
True
}))
self
.
assertNumberMigrations
(
changes
,
'testapp'
,
1
)
self
.
assertMigrationDependencies
(
changes
,
'testapp'
,
0
,
[(
'otherapp'
,
'__first__'
)])
self
.
assertOperationTypes
(
changes
,
'testapp'
,
0
,
[
'RenameModel'
])
self
.
assertOperationAttributes
(
changes
,
'testapp'
,
0
,
0
,
old_name
=
'EntityA'
,
new_name
=
'RenamedEntityA'
)
def
test_fk_dependency
(
self
):
def
test_fk_dependency
(
self
):
"""Having a ForeignKey automatically adds a dependency."""
"""Having a ForeignKey automatically adds a dependency."""
# Note that testapp (author) has no dependencies,
# Note that testapp (author) has no dependencies,
...
...
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