Estudio SAG
Estudio SAG

Reputation: 13

Django Ñ problem? ValueError: source code string cannot contain null bytes

I'm working on Django and connecting to a remote SQL Server database.

  1. I conected to the remote db with this parameters: the db is in sql server 2019, and uses Modern_Spanish_CI_AS
'default': {
       'ENGINE': 'mssql',
        'NAME': '*******',
        'USER': '*****',
        'PASSWORD': '******',
        'HOST': '*******',
        'PORT': '15016',
        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
            
        }, 
  1. Then i ran
python manage.py inspectdb --database=default --include-views > vistas_generados.py
  1. In vistas_generados.py I found several characters like this: "±" replacing the letter Ñ in the original database.
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'  
  1. 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

  2. i used class VwWebAlumnos in my views.py file importing it from vistas_generados.py

  3. 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:

Upvotes: 0

Views: 77

Answers (0)

Related Questions