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: