From 7b99ce052c5a2980ad66de26deb357fb95e4baf5 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 19 Apr 2023 15:22:36 +0800 Subject: [PATCH] bugfix --- sqlor/ddl_template_mysql.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sqlor/ddl_template_mysql.py b/sqlor/ddl_template_mysql.py index e85249d..8b39434 100755 --- a/sqlor/ddl_template_mysql.py +++ b/sqlor/ddl_template_mysql.py @@ -25,6 +25,11 @@ longblob {{type}} {%- endif %} {%- endmacro %} + +{%- macro defaultValue(defaultv) %} +{%- if defaultv %} DEFAULT '{{defaultv}}'{%- endif -%} +{%- endmacro %} + {% macro nullStr(nullable) %} {%- if nullable=='no' -%} NOT NULL @@ -37,7 +42,7 @@ drop table if exists {{summary[0].name}}; CREATE TABLE {{summary[0].name}} ( {% for field in fields %} - `{{field.name}}` {{typeStr(field.type,field.length,field.dec)}} {{nullStr(field.nullable)}} {%if field.title -%} comment '{{field.title}}'{%- endif %}{%- if not loop.last -%},{%- endif -%} + `{{field.name}}` {{typeStr(field.type,field.length,field.dec)}} {{nullStr(field.nullable)}} {{defaultValue(field.default)}} {%if field.title -%} comment '{{field.title}}'{%- endif %}{%- if not loop.last -%},{%- endif -%} {% endfor %} {% if summary[0].primary and len(summary[0].primary)>0 %} {{primary()}}