From e1bbcd73abb499e4d30407836a2e5dd614cfb3a9 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Thu, 16 Nov 2023 13:39:42 +0530 Subject: [PATCH] fix: 0 is falsy, set correct defaults Signed-off-by: Akhil Narang --- frappe/database/postgres/schema.py | 7 ++++--- frappe/database/schema.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/frappe/database/postgres/schema.py b/frappe/database/postgres/schema.py index fa00c2fe78..946747aa47 100644 --- a/frappe/database/postgres/schema.py +++ b/frappe/database/postgres/schema.py @@ -143,12 +143,13 @@ class PostgresTable(DBTable): change_nullability = [] for col in self.change_nullability: + default = col.default or get_not_null_defaults(col.fieldtype) + if isinstance(default, str): + default = frappe.db.escape(default) change_nullability.append( f"ALTER COLUMN \"{col.fieldname}\" {'SET' if col.not_nullable else 'DROP'} NOT NULL" ) - change_nullability.append( - f'ALTER COLUMN "{col.fieldname}" SET DEFAULT {col.default or frappe.db.escape(col.default)}' - ) + change_nullability.append(f'ALTER COLUMN "{col.fieldname}" SET DEFAULT {default}') if col.not_nullable: try: diff --git a/frappe/database/schema.py b/frappe/database/schema.py index 621513bf99..497336cd7b 100644 --- a/frappe/database/schema.py +++ b/frappe/database/schema.py @@ -209,7 +209,7 @@ class DbColumn: return column_def null = True - default = "" + default = None unique = False if self.fieldtype in ("Check", "Int"): @@ -240,7 +240,7 @@ class DbColumn: if not null: column_def += " NOT NULL" - if default: + if default is not None: column_def += f" DEFAULT {default}" if unique: