django指定表编码,⽣成表comment,⽣成表字段默认值到xxxx\django\db\backends\base\schema.py编辑
表指定utf8mb4编码
def table_sql(self, model):
# ....
# 表指定btf8mb4编码, 加上下⾯这⼀⾏
sql += ' default charset=utf8mb4 COLLATE utf8mb4_general_ci'
return sql, params
字段⽣成comment
def column_sql(self, model, field, include_default=False):
# ...
# 增加针对mysql注释的处理, 使⽤help_text
utable_name == 'mysql' and field.help_text:
sql += " COMMENT '%s'" % field.help_text
# Return the sql
return sql, params
字段默认值
def column_sql(self, model, field, include_default=False):
# ...
# 注释这⼀⾏, 调⽤的地⽅没有传值,永远为false
# include_default = include_default and not self.skip_default(field)
# 设置数据默认值
include_default = False if sql in ['longtext', 'longblob', 'json'] utable_name != 'mysql' else True
if include_default:
default_value = self.effective_default(field)
column_default = ' DEFAULT ' + self._column_default_sql(field)
if default_value is not None:
# 针对auto_now_add和auto_now的设置默认值为current_timestamp(6)
utable_name == 'mysql' and (getattr(field, 'auto_now', False) or getattr(field, 'auto_now_add', False)):
sql += column_default % 'current_timestamp(6)'
quires_literal_defaults:
# Some databases can't take defaults as a parameter (oracle)
# If this is the case, the individual schema backend should
# implement prepare_default
sql += column_default % self.prepare_default(default_value)
else:
django登录注册功能
sql += column_default
params += [default_value]
# ...

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。