Reputation: 13
I'm working on Django and connecting to a remote SQL Server database.
'default': {
'ENGINE': 'mssql',
'NAME': '*******',
'USER': '*****',
'PASSWORD': '******',
'HOST': '*******',
'PORT': '15016',
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server',
},
python manage.py inspectdb --database=default --include-views > vistas_generados.py
class VwWebAlumnos(models.Model):
compa±ero1 = models.CharField(db_column='COMPAÐERO1', max_length=50,
blank=True, null=True)
class Meta:
managed = False # Created from a view. Don't remove.
db_table = 'VW_WEB_ALUMNOS'
i replace the "±" for any letter and the error goes away, but, of course the whole file is still encoded in a different collation than UTF-8. Its in UTF-16LE
i used class VwWebAlumnos in my views.py file importing it from vistas_generados.py
when i ran the server y got this error
File "C:\Users\Usuario\Pictures\Hipocampo\HPC\hpc\USERDATA\views.py", line 6, in <module>
from vistas_generados import VwWebActividades
ValueError: source code string cannot contain null bytes
I suspect that the problem is related to the database being encoding in Modern_Spanish_CI_AS and the way the Ñ character is being translated to vistas_generados.py when i ran inspectdb
So far, I've tried the following:
changing the encoding in vistas_generados.py to other collations, and that makes the whole file goes red in mistakes.
In settings.py, in database options:
'unicode_results': True and also 'extra_params': 'ClientCharset=utf8'
Modifying in base.py: mssql: unicode_results = options.get('unicode_results', True)
Some less elegant solutions like opening the generated file with Notepad and saving it in UTF-8 or ISO 8859-1
Upvotes: 0
Views: 77