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
16614dcd
Kaydet (Commit)
16614dcd
authored
Haz 25, 2016
tarafından
Jon Dufresne
Kaydeden (comit)
Tim Graham
Haz 29, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #25694 -- Removed incorrect _uniq suffix on index names during migrations.
üst
a84344bc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
3 deletions
+27
-3
schema.py
django/db/backends/base/schema.py
+1
-1
models.py
tests/schema/models.py
+1
-0
tests.py
tests/schema/tests.py
+25
-2
No files found.
django/db/backends/base/schema.py
Dosyayı görüntüle @
16614dcd
...
...
@@ -692,7 +692,7 @@ class BaseDatabaseSchemaEditor(object):
if
(
not
old_field
.
db_index
and
new_field
.
db_index
and
not
new_field
.
unique
and
not
(
not
old_field
.
unique
and
new_field
.
unique
)):
self
.
execute
(
self
.
_create_index_sql
(
model
,
[
new_field
]
,
suffix
=
"_uniq"
))
self
.
execute
(
self
.
_create_index_sql
(
model
,
[
new_field
]))
# Type alteration on primary key? Then we need to alter the column
# referring to us.
rels_to_update
=
[]
...
...
tests/schema/models.py
Dosyayı görüntüle @
16614dcd
...
...
@@ -12,6 +12,7 @@ new_apps = Apps()
class
Author
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
255
)
height
=
models
.
PositiveIntegerField
(
null
=
True
,
blank
=
True
)
weight
=
models
.
IntegerField
(
null
=
True
,
blank
=
True
)
class
Meta
:
apps
=
new_apps
...
...
tests/schema/tests.py
Dosyayı görüntüle @
16614dcd
...
...
@@ -1773,7 +1773,7 @@ class SchemaTests(TransactionTestCase):
editor
.
alter_field
(
Author
,
old_field
,
new_field
,
strict
=
True
)
self
.
assertEqual
(
self
.
get_constraints_for_column
(
Author
,
'name'
),
[
'schema_author_
name_1fbc5617_like'
,
'schema_author_name_1fbc5617_uniq
'
]
[
'schema_author_
b068931c'
,
'schema_author_name_1fbc5617_like
'
]
)
# Remove db_index=True to drop both indexes.
with
connection
.
schema_editor
()
as
editor
:
...
...
@@ -1794,7 +1794,7 @@ class SchemaTests(TransactionTestCase):
editor
.
alter_field
(
Note
,
old_field
,
new_field
,
strict
=
True
)
self
.
assertEqual
(
self
.
get_constraints_for_column
(
Note
,
'info'
),
[
'schema_note_
info_4b0ea695_like'
,
'schema_note_info_4b0ea695_uniq
'
]
[
'schema_note_
caf9b6b9'
,
'schema_note_info_4b0ea695_like
'
]
)
# Remove db_index=True to drop both indexes.
with
connection
.
schema_editor
()
as
editor
:
...
...
@@ -1859,6 +1859,29 @@ class SchemaTests(TransactionTestCase):
[
'schema_tag_slug_2c418ba3_like'
,
'schema_tag_slug_key'
]
)
def
test_alter_field_add_index_to_integerfield
(
self
):
# Create the table and verify no initial indexes.
with
connection
.
schema_editor
()
as
editor
:
editor
.
create_model
(
Author
)
self
.
assertEqual
(
self
.
get_constraints_for_column
(
Author
,
'weight'
),
[])
# Alter to add db_index=True and create index.
old_field
=
Author
.
_meta
.
get_field
(
'weight'
)
new_field
=
IntegerField
(
null
=
True
,
db_index
=
True
)
new_field
.
set_attributes_from_name
(
'weight'
)
with
connection
.
schema_editor
()
as
editor
:
editor
.
alter_field
(
Author
,
old_field
,
new_field
,
strict
=
True
)
expected
=
'schema_author_7edabf99'
if
connection
.
features
.
uppercases_column_names
:
expected
=
expected
.
upper
()
self
.
assertEqual
(
self
.
get_constraints_for_column
(
Author
,
'weight'
),
[
expected
])
# Remove db_index=True to drop index.
with
connection
.
schema_editor
()
as
editor
:
editor
.
alter_field
(
Author
,
new_field
,
old_field
,
strict
=
True
)
self
.
assertEqual
(
self
.
get_constraints_for_column
(
Author
,
'weight'
),
[])
def
test_alter_pk_with_self_referential_field
(
self
):
"""
Changing the primary key field name of a model with a self-referential
...
...
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