django-pyodbc-azure
django-pyodbc-azure copied to clipboard
CharField always create nvarchar type - possible to change to varchar?
The CharField create column type of nvarchar by default - is it possible to change from nvarchar to varchar?
Thanks
my solution is define you own django field define varchar field class VarCharField(models.Field):
def __init__(self, max_length, *args, **kwargs):
self.max_length = max_length
super(VarCharField, self).__init__(max_length=max_length, *args, **kwargs)
def db_type(self, connection):
"""
限定生成数据库表的字段类型为 char,长度为 max_length 指定的值
"""
return 'varchar(%s)' % self.max_length
then use it in models.py
a = VarCharField(max_length=64)
I know this is a very old issue and response, but does it work? I have been trying to change the main database wrapper in my project to apply specific formats to varchar and dates. However, I don't know how to do it, without modifying base.py .
@johnson329, My Django project has several apps, each with its own models.py file. Where you recomend to add this class modification to affect all apps?