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
3efd1b8b
Kaydet (Commit)
3efd1b8b
authored
Ara 22, 2013
tarafından
Ramiro Morales
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #21692 -- Quote table name when creating it.
üst
efddae25
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
3 deletions
+40
-3
schema.py
django/db/backends/schema.py
+1
-1
models.py
tests/schema/models.py
+13
-0
tests.py
tests/schema/tests.py
+26
-2
No files found.
django/db/backends/schema.py
Dosyayı görüntüle @
3efd1b8b
...
...
@@ -227,7 +227,7 @@ class BaseDatabaseSchemaEditor(object):
})
# Make the table
sql
=
self
.
sql_create_table
%
{
"table"
:
model
.
_meta
.
db_table
,
"table"
:
self
.
quote_name
(
model
.
_meta
.
db_table
)
,
"definition"
:
", "
.
join
(
column_sqls
)
}
self
.
execute
(
sql
,
params
)
...
...
tests/schema/models.py
Dosyayı görüntüle @
3efd1b8b
from
django.apps.registry
import
Apps
from
django.db
import
models
from
django.utils.encoding
import
python_2_unicode_compatible
# Because we want to test creation and deletion of these as separate things,
# these models are all inserted into a separate Apps so the main test
...
...
@@ -102,3 +103,15 @@ class BookWithLongName(models.Model):
class
Meta
:
apps
=
new_apps
# Based on tests/reserved_names/models.py
@python_2_unicode_compatible
class
Thing
(
models
.
Model
):
when
=
models
.
CharField
(
max_length
=
1
,
primary_key
=
True
)
class
Meta
:
db_table
=
'select'
def
__str__
(
self
):
return
self
.
when
tests/schema/tests.py
Dosyayı görüntüle @
3efd1b8b
...
...
@@ -3,13 +3,13 @@ import datetime
import
unittest
from
django.test
import
TransactionTestCase
from
django.db
import
connection
,
DatabaseError
,
IntegrityError
from
django.db
import
connection
,
DatabaseError
,
IntegrityError
,
OperationalError
from
django.db.models.fields
import
IntegerField
,
TextField
,
CharField
,
SlugField
from
django.db.models.fields.related
import
ManyToManyField
,
ForeignKey
from
django.db.transaction
import
atomic
from
.models
import
(
Author
,
AuthorWithM2M
,
Book
,
BookWithLongName
,
BookWithSlug
,
BookWithM2M
,
Tag
,
TagIndexed
,
TagM2MTest
,
TagUniqueRename
,
UniqueTest
)
UniqueTest
,
Thing
)
class
SchemaTests
(
TransactionTestCase
):
...
...
@@ -26,6 +26,7 @@ class SchemaTests(TransactionTestCase):
models
=
[
Author
,
AuthorWithM2M
,
Book
,
BookWithLongName
,
BookWithSlug
,
BookWithM2M
,
Tag
,
TagIndexed
,
TagM2MTest
,
TagUniqueRename
,
UniqueTest
,
Thing
]
# Utility functions
...
...
@@ -683,3 +684,26 @@ class SchemaTests(TransactionTestCase):
column_name
,
connection
.
introspection
.
get_indexes
(
connection
.
cursor
(),
BookWithLongName
.
_meta
.
db_table
),
)
def
test_creation_deletion_reserved_names
(
self
):
"""
Tries creating a model's table, and then deleting it when it has a
SQL reserved name.
"""
# Create the table
with
connection
.
schema_editor
()
as
editor
:
try
:
editor
.
create_model
(
Thing
)
except
OperationalError
as
e
:
self
.
fail
(
"Errors when applying initial migration for a model "
"with a table named after a SQL reserved word:
%
s"
%
e
)
# Check that it's there
list
(
Thing
.
objects
.
all
())
# Clean up that table
with
connection
.
schema_editor
()
as
editor
:
editor
.
delete_model
(
Thing
)
# Check that it's gone
self
.
assertRaises
(
DatabaseError
,
lambda
:
list
(
Thing
.
objects
.
all
()),
)
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