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
003334f8
Kaydet (Commit)
003334f8
authored
Nis 11, 2018
tarafından
Jeremy Bowman
Kaydeden (comit)
Tim Graham
Nis 12, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Tested altering a unique field when a reverse M2M relation exists.
üst
99539ca3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
1 deletion
+37
-1
tests.py
tests/schema/tests.py
+37
-1
No files found.
tests/schema/tests.py
Dosyayı görüntüle @
003334f8
...
...
@@ -22,7 +22,7 @@ from django.db.transaction import TransactionManagementError, atomic
from
django.test
import
(
TransactionTestCase
,
skipIfDBFeature
,
skipUnlessDBFeature
,
)
from
django.test.utils
import
CaptureQueriesContext
,
isolate_apps
from
django.test.utils
import
CaptureQueriesContext
,
isolate_apps
,
patch_logger
from
django.utils
import
timezone
from
.fields
import
(
...
...
@@ -1545,6 +1545,42 @@ class SchemaTests(TransactionTestCase):
TagUniqueRename
.
objects
.
create
(
title
=
"bar"
,
slug2
=
"foo"
)
Tag
.
objects
.
all
()
.
delete
()
@isolate_apps
(
'schema'
)
@unittest.skipIf
(
connection
.
vendor
==
'sqlite'
,
'SQLite remakes the table on field alteration.'
)
def
test_unique_and_reverse_m2m
(
self
):
"""
AlterField can modify a unique field when there's a reverse M2M
relation on the model.
"""
class
Tag
(
Model
):
title
=
CharField
(
max_length
=
255
)
slug
=
SlugField
(
unique
=
True
)
class
Meta
:
app_label
=
'schema'
class
Book
(
Model
):
tags
=
ManyToManyField
(
Tag
,
related_name
=
'books'
)
class
Meta
:
app_label
=
'schema'
with
connection
.
schema_editor
()
as
editor
:
editor
.
create_model
(
Tag
)
editor
.
create_model
(
Book
)
new_field
=
SlugField
(
max_length
=
75
,
unique
=
True
)
new_field
.
model
=
Tag
new_field
.
set_attributes_from_name
(
'slug'
)
with
patch_logger
(
'django.db.backends.schema'
,
'debug'
)
as
logger_calls
:
with
connection
.
schema_editor
()
as
editor
:
editor
.
alter_field
(
Tag
,
Tag
.
_meta
.
get_field
(
'slug'
),
new_field
)
# One SQL statement is executed to alter the field.
self
.
assertEqual
(
len
(
logger_calls
),
1
)
# Ensure that the field is still unique.
Tag
.
objects
.
create
(
title
=
'foo'
,
slug
=
'foo'
)
with
self
.
assertRaises
(
IntegrityError
):
Tag
.
objects
.
create
(
title
=
'bar'
,
slug
=
'foo'
)
def
test_unique_together
(
self
):
"""
Tests removing and adding unique_together constraints on a model.
...
...
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