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
f65d4db8
Kaydet (Commit)
f65d4db8
authored
May 26, 2015
tarafından
Andriy Sokolovskiy
Kaydeden (comit)
Tim Graham
May 28, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
[1.8.x] Fixed #24817 -- Prevented loss of null info in MySQL field renaming.
Backport of
80ad5472
from master
üst
df6a4cac
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
67 additions
and
11 deletions
+67
-11
schema.py
django/db/backends/base/schema.py
+9
-6
schema.py
django/db/backends/mysql/schema.py
+14
-3
1.7.9.txt
docs/releases/1.7.9.txt
+10
-0
1.8.3.txt
docs/releases/1.8.3.txt
+3
-0
index.txt
docs/releases/index.txt
+1
-0
models.py
tests/schema/models.py
+8
-0
tests.py
tests/schema/tests.py
+22
-2
No files found.
django/db/backends/base/schema.py
Dosyayı görüntüle @
f65d4db8
...
...
@@ -544,12 +544,7 @@ class BaseDatabaseSchemaEditor(object):
self
.
execute
(
self
.
_delete_constraint_sql
(
self
.
sql_delete_check
,
model
,
constraint_name
))
# Have they renamed the column?
if
old_field
.
column
!=
new_field
.
column
:
self
.
execute
(
self
.
sql_rename_column
%
{
"table"
:
self
.
quote_name
(
model
.
_meta
.
db_table
),
"old_column"
:
self
.
quote_name
(
old_field
.
column
),
"new_column"
:
self
.
quote_name
(
new_field
.
column
),
"type"
:
new_type
,
})
self
.
execute
(
self
.
_rename_field_sql
(
model
.
_meta
.
db_table
,
old_field
,
new_field
,
new_type
))
# Next, start accumulating actions to do
actions
=
[]
null_actions
=
[]
...
...
@@ -866,6 +861,14 @@ class BaseDatabaseSchemaEditor(object):
output
.
append
(
self
.
_create_index_sql
(
model
,
fields
,
suffix
=
"_idx"
))
return
output
def
_rename_field_sql
(
self
,
table
,
old_field
,
new_field
,
new_type
):
return
self
.
sql_rename_column
%
{
"table"
:
self
.
quote_name
(
table
),
"old_column"
:
self
.
quote_name
(
old_field
.
column
),
"new_column"
:
self
.
quote_name
(
new_field
.
column
),
"type"
:
new_type
,
}
def
_create_fk_sql
(
self
,
model
,
field
,
suffix
):
from_table
=
model
.
_meta
.
db_table
from_column
=
field
.
column
...
...
django/db/backends/mysql/schema.py
Dosyayı görüntüle @
f65d4db8
...
...
@@ -80,10 +80,21 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
)
return
super
(
DatabaseSchemaEditor
,
self
)
.
_delete_composed_index
(
model
,
fields
,
*
args
)
def
_alter_column_type_sql
(
self
,
table
,
old_field
,
new_field
,
new_type
):
# Keep null property of old field, if it has changed, it will be handled separately
if
old_field
.
null
:
def
_set_field_new_type_null_status
(
self
,
field
,
new_type
):
"""
Keep the null property of the old field. If it has changed, it will be
handled separately.
"""
if
field
.
null
:
new_type
+=
" NULL"
else
:
new_type
+=
" NOT NULL"
return
new_type
def
_alter_column_type_sql
(
self
,
table
,
old_field
,
new_field
,
new_type
):
new_type
=
self
.
_set_field_new_type_null_status
(
old_field
,
new_type
)
return
super
(
DatabaseSchemaEditor
,
self
)
.
_alter_column_type_sql
(
table
,
old_field
,
new_field
,
new_type
)
def
_rename_field_sql
(
self
,
table
,
old_field
,
new_field
,
new_type
):
new_type
=
self
.
_set_field_new_type_null_status
(
old_field
,
new_type
)
return
super
(
DatabaseSchemaEditor
,
self
)
.
_rename_field_sql
(
table
,
old_field
,
new_field
,
new_type
)
docs/releases/1.7.9.txt
0 → 100644
Dosyayı görüntüle @
f65d4db8
==========================
Django 1.7.9 release notes
==========================
*Under development*
Django 1.7.9 fixes several bugs in 1.7.8.
* Prevented the loss of ``null``/``not null`` column properties during field
renaming of MySQL databases (:ticket:`24817`).
docs/releases/1.8.3.txt
Dosyayı görüntüle @
f65d4db8
...
...
@@ -25,3 +25,6 @@ Bugfixes
* Fixed a regression which caused template context processors to overwrite
variables set on a ``RequestContext`` after it's created (:ticket:`24847`).
* Prevented the loss of ``null``/``not null`` column properties during field
renaming of MySQL databases (:ticket:`24817`).
docs/releases/index.txt
Dosyayı görüntüle @
f65d4db8
...
...
@@ -35,6 +35,7 @@ versions of the documentation contain the release notes for any later releases.
.. toctree::
:maxdepth: 1
1.7.9
1.7.8
1.7.7
1.7.6
...
...
tests/schema/models.py
Dosyayı görüntüle @
f65d4db8
...
...
@@ -87,6 +87,14 @@ class Note(models.Model):
apps
=
new_apps
class
NoteRename
(
models
.
Model
):
detail_info
=
models
.
TextField
()
class
Meta
:
apps
=
new_apps
db_table
=
"schema_note"
class
Tag
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
255
)
slug
=
models
.
SlugField
(
unique
=
True
)
...
...
tests/schema/tests.py
Dosyayı görüntüle @
f65d4db8
...
...
@@ -20,8 +20,8 @@ from django.test import TransactionTestCase, skipIfDBFeature
from
.fields
import
CustomManyToManyField
,
InheritedManyToManyField
from
.models
import
(
Author
,
AuthorWithDefaultHeight
,
AuthorWithEvenLongerName
,
Book
,
BookWeak
,
BookWithLongName
,
BookWithO2O
,
BookWithSlug
,
Note
,
Tag
,
TagIndexed
,
TagM2MTest
,
TagUniqueRename
,
Thing
,
UniqueTest
,
new_apps
,
BookWithLongName
,
BookWithO2O
,
BookWithSlug
,
Note
,
NoteRename
,
Tag
,
Tag
Indexed
,
Tag
M2MTest
,
TagUniqueRename
,
Thing
,
UniqueTest
,
new_apps
,
)
...
...
@@ -751,6 +751,26 @@ class SchemaTests(TransactionTestCase):
self
.
assertEqual
(
columns
[
'display_name'
][
0
],
"CharField"
)
self
.
assertNotIn
(
"name"
,
columns
)
@skipIfDBFeature
(
'interprets_empty_strings_as_nulls'
)
def
test_rename_keep_null_status
(
self
):
"""
Renaming a field shouldn't affect the not null status.
"""
with
connection
.
schema_editor
()
as
editor
:
editor
.
create_model
(
Note
)
with
self
.
assertRaises
(
IntegrityError
):
Note
.
objects
.
create
(
info
=
None
)
old_field
=
Note
.
_meta
.
get_field
(
"info"
)
new_field
=
TextField
()
new_field
.
set_attributes_from_name
(
"detail_info"
)
with
connection
.
schema_editor
()
as
editor
:
editor
.
alter_field
(
Note
,
old_field
,
new_field
,
strict
=
True
)
columns
=
self
.
column_classes
(
Note
)
self
.
assertEqual
(
columns
[
'detail_info'
][
0
],
"TextField"
)
self
.
assertNotIn
(
"info"
,
columns
)
with
self
.
assertRaises
(
IntegrityError
):
NoteRename
.
objects
.
create
(
detail_info
=
None
)
def
_test_m2m_create
(
self
,
M2MFieldClass
):
"""
Tests M2M fields on models during creation
...
...
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