3
3
from django .db .backends .base .schema import BaseDatabaseSchemaEditor
4
4
from django .db import NotSupportedError
5
5
6
+
6
7
class DatabaseSchemaEditor (BaseDatabaseSchemaEditor ):
7
8
sql_alter_column_type = "ALTER COLUMN %(column)s %(type)s"
8
9
sql_alter_column_null = "ALTER COLUMN %(column)s NULL"
9
10
11
+ # Fix for correct alter column syntax
12
+ # ALTER TABLE tablename ALTER COLUMN oldname RENAME newname
13
+ sql_rename_column = (
14
+ "ALTER TABLE %(table)s ALTER COLUMN %(old_column)s RENAME %(new_column)s"
15
+ )
16
+
17
+ sql_rename_table = "ALTER TABLE %(old_table)s RENAME %(new_table)s"
18
+
10
19
def quote_value (self , value ):
11
20
if isinstance (value , bool ):
12
21
return str (int (value ))
@@ -26,4 +35,25 @@ def table_sql(self, model):
26
35
raise NotSupportedError (
27
36
"Invalid table name '%s'" % (model ._meta .db_table )
28
37
)
29
- return super ().table_sql (model )
38
+ return super ().table_sql (model )
39
+
40
+ def skip_default_on_alter (self , field ):
41
+ """
42
+ Some backends don't accept default values for certain columns types
43
+ (i.e. MySQL longtext and longblob) in the ALTER COLUMN statement.
44
+ """
45
+ return True
46
+
47
+ # Due to DP-412796 and DP-412798 disable default fields
48
+ # on alter statements
49
+ def skip_default (self , field ):
50
+ # return super().skip_default(field)
51
+ return True
52
+
53
+ # def _rename_field_sql(self, table, old_field, new_field, new_type):
54
+ # return self.sql_rename_column % {
55
+ # "table": self.quote_name(table),
56
+ # "old_column": self.quote_name(old_field.column),
57
+ # "new_column": self.quote_name(new_field.column),
58
+ # "type": new_type,
59
+ # }
0 commit comments