Merge pull request #1433 from anandpdoshi/fix/int-float-not-null-patch
[fix] alter column for int, float not null
This commit is contained in:
commit
4c21450dc0
2 changed files with 15 additions and 1 deletions
|
|
@ -18,7 +18,7 @@ execute:frappe.db.sql("delete from `tabDocField` where parent='0'")
|
|||
frappe.patches.v4_0.change_varchar_length
|
||||
frappe.patches.v6_4.reduce_varchar_length
|
||||
frappe.patches.v5_2.change_checks_to_not_null
|
||||
frappe.patches.v6_9.int_float_not_null
|
||||
frappe.patches.v6_9.int_float_not_null #2015-11-25
|
||||
frappe.patches.v5_0.v4_to_v5
|
||||
|
||||
frappe.patches.v5_0.remove_shopping_cart_app
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.utils import cint, flt
|
||||
|
||||
def execute():
|
||||
for doctype in frappe.get_all("DocType", filters={"issingle": 0}):
|
||||
doctype = doctype.name
|
||||
meta = frappe.get_meta(doctype)
|
||||
|
||||
for column in frappe.db.sql("desc `tab{doctype}`".format(doctype=doctype), as_dict=True):
|
||||
fieldname = column["Field"]
|
||||
|
|
@ -14,3 +16,15 @@ def execute():
|
|||
|
||||
frappe.db.sql("""update `tab{doctype}` set `{fieldname}`=0 where `{fieldname}` is null"""\
|
||||
.format(doctype=doctype, fieldname=fieldname))
|
||||
|
||||
# alter table
|
||||
if column["Null"]=='YES':
|
||||
if not meta.get_field(fieldname):
|
||||
continue
|
||||
|
||||
default = cint(column["Default"]) if column_type.startswith("int") else flt(column["Default"])
|
||||
frappe.db.sql_ddl("""alter table `tab{doctype}`
|
||||
change `{fieldname}` `{fieldname}` {column_type} not null default '{default}'""".format(
|
||||
doctype=doctype, fieldname=fieldname, column_type=column_type, default=default))
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue