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
5a424c23
Kaydet (Commit)
5a424c23
authored
Eyl 17, 2013
tarafından
Markus Holtermann
Kaydeden (comit)
Tim Graham
Eyl 17, 2013
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #21114 -- Migrations must not have a dependency to themselves.
üst
73a610d2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
2 deletions
+59
-2
autodetector.py
django/db/migrations/autodetector.py
+4
-2
test_autodetector.py
tests/migrations/test_autodetector.py
+55
-0
No files found.
django/db/migrations/autodetector.py
Dosyayı görüntüle @
5a424c23
...
...
@@ -106,7 +106,8 @@ class MigrationAutodetector(object):
)
)
for
field_name
,
other_app_label
,
other_model_name
in
related_fields
:
self
.
add_dependency
(
app_label
,
other_app_label
)
if
app_label
!=
other_app_label
:
self
.
add_dependency
(
app_label
,
other_app_label
)
del
pending_add
[
app_label
,
model_name
]
# Ah well, we'll need to split one. Pick deterministically.
else
:
...
...
@@ -140,7 +141,8 @@ class MigrationAutodetector(object):
),
new
=
True
,
)
self
.
add_dependency
(
app_label
,
other_app_label
)
if
app_label
!=
other_app_label
:
self
.
add_dependency
(
app_label
,
other_app_label
)
# Removing models
removed_models
=
set
(
old_model_keys
)
-
set
(
new_model_keys
)
for
app_label
,
model_name
in
removed_models
:
...
...
tests/migrations/test_autodetector.py
Dosyayı görüntüle @
5a424c23
...
...
@@ -16,8 +16,11 @@ class AutodetectorTests(TestCase):
author_name_longer
=
ModelState
(
"testapp"
,
"Author"
,
[(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"name"
,
models
.
CharField
(
max_length
=
400
))])
author_name_renamed
=
ModelState
(
"testapp"
,
"Author"
,
[(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"names"
,
models
.
CharField
(
max_length
=
200
))])
author_with_book
=
ModelState
(
"testapp"
,
"Author"
,
[(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"name"
,
models
.
CharField
(
max_length
=
200
)),
(
"book"
,
models
.
ForeignKey
(
"otherapp.Book"
))])
author_with_publisher
=
ModelState
(
"testapp"
,
"Author"
,
[(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"name"
,
models
.
CharField
(
max_length
=
200
)),
(
"publisher"
,
models
.
ForeignKey
(
"testapp.Publisher"
))])
author_proxy
=
ModelState
(
"testapp"
,
"AuthorProxy"
,
[],
{
"proxy"
:
True
},
(
"testapp.author"
,
))
author_proxy_notproxy
=
ModelState
(
"testapp"
,
"AuthorProxy"
,
[],
{},
(
"testapp.author"
,
))
publisher
=
ModelState
(
"testapp"
,
"Publisher"
,
[(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"name"
,
models
.
CharField
(
max_length
=
100
))])
publisher_with_author
=
ModelState
(
"testapp"
,
"Publisher"
,
[(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"author"
,
models
.
ForeignKey
(
"testapp.Author"
)),
(
"name"
,
models
.
CharField
(
max_length
=
100
))])
other_pony
=
ModelState
(
"otherapp"
,
"Pony"
,
[(
"id"
,
models
.
AutoField
(
primary_key
=
True
))])
other_stable
=
ModelState
(
"otherapp"
,
"Stable"
,
[(
"id"
,
models
.
AutoField
(
primary_key
=
True
))])
third_thing
=
ModelState
(
"thirdapp"
,
"Thing"
,
[(
"id"
,
models
.
AutoField
(
primary_key
=
True
))])
...
...
@@ -205,6 +208,29 @@ class AutodetectorTests(TestCase):
self
.
assertEqual
(
migration2
.
dependencies
,
[(
"testapp"
,
"auto_1"
)])
self
.
assertEqual
(
migration3
.
dependencies
,
[(
"otherapp"
,
"auto_1"
)])
def
test_same_app_no_fk_dependency
(
self
):
"""
Tests that a migration with a FK between two models of the same app
does not have a dependency to itself.
"""
# Make state
before
=
self
.
make_project_state
([])
after
=
self
.
make_project_state
([
self
.
author_with_publisher
,
self
.
publisher
])
autodetector
=
MigrationAutodetector
(
before
,
after
)
changes
=
autodetector
.
_detect_changes
()
# Right number of migrations?
self
.
assertEqual
(
len
(
changes
[
'testapp'
]),
1
)
# Right number of actions?
migration
=
changes
[
'testapp'
][
0
]
self
.
assertEqual
(
len
(
migration
.
operations
),
2
)
# Right actions?
action
=
migration
.
operations
[
0
]
self
.
assertEqual
(
action
.
__class__
.
__name__
,
"CreateModel"
)
action
=
migration
.
operations
[
1
]
self
.
assertEqual
(
action
.
__class__
.
__name__
,
"CreateModel"
)
# Right dependencies?
self
.
assertEqual
(
migration
.
dependencies
,
[])
def
test_circular_fk_dependency
(
self
):
"""
Tests that having a circular ForeignKey dependency automatically
...
...
@@ -239,6 +265,35 @@ class AutodetectorTests(TestCase):
self
.
assertEqual
(
migration2
.
dependencies
,
[])
self
.
assertEqual
(
set
(
migration3
.
dependencies
),
set
([(
"otherapp"
,
"auto_1"
),
(
"testapp"
,
"auto_1"
)]))
def
test_same_app_circular_fk_dependency
(
self
):
"""
Tests that a migration with a FK between two models of the same app
does not have a dependency to itself.
"""
# Make state
before
=
self
.
make_project_state
([])
after
=
self
.
make_project_state
([
self
.
author_with_publisher
,
self
.
publisher_with_author
])
autodetector
=
MigrationAutodetector
(
before
,
after
)
changes
=
autodetector
.
_detect_changes
()
# Right number of migrations?
self
.
assertEqual
(
len
(
changes
[
'testapp'
]),
2
)
# Right number of actions?
migration1
=
changes
[
'testapp'
][
0
]
self
.
assertEqual
(
len
(
migration1
.
operations
),
2
)
migration2
=
changes
[
'testapp'
][
1
]
self
.
assertEqual
(
len
(
migration2
.
operations
),
1
)
# Right actions?
action
=
migration1
.
operations
[
0
]
self
.
assertEqual
(
action
.
__class__
.
__name__
,
"CreateModel"
)
action
=
migration1
.
operations
[
1
]
self
.
assertEqual
(
action
.
__class__
.
__name__
,
"CreateModel"
)
action
=
migration2
.
operations
[
0
]
self
.
assertEqual
(
action
.
__class__
.
__name__
,
"AddField"
)
self
.
assertEqual
(
action
.
name
,
"publisher"
)
# Right dependencies?
self
.
assertEqual
(
migration1
.
dependencies
,
[])
self
.
assertEqual
(
migration2
.
dependencies
,
[(
"testapp"
,
"auto_1"
)])
def
test_unique_together
(
self
):
"Tests unique_together detection"
# Make state
...
...
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