michiya / django-pyodbc-azure

Django backend for Microsoft SQL Server and Azure SQL Database using pyodbc
https://pypi.python.org/pypi/django-pyodbc-azure
BSD 3-Clause "New" or "Revised" License
321 stars 140 forks source link

Access model with other schema #222

Open wgf4242 opened 3 years ago

wgf4242 commented 3 years ago

Set schema in db_table not work. How to make it work?

# models.py
class Example(models.Model):
    lsid = models.IntegerField(db_column='Lsid', primary_key=True)  # Field name made lowercase.

    class Meta:
        db_table = "[Jfwd].[T_DX_Yjfs]"

Example.objects.all()

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File ":D:\py\django\db\models\query.py", line 244, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File ":D:\py\django\db\models\query.py", line 250, in __len__
    self._fetch_all()
  File ":D:\py\django\db\models\query.py", line 1186, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File ":D:\py\django\db\models\query.py", line 54, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File ":D:\py\django\db\models\sql\compiler.py", line 1098, in execute_sql
    cursor.execute(sql, params)
  File ":D:\py\django\db\backends\utils.py", line 100, in execute
    return super().execute(sql, params)
  File ":D:\py\django\db\backends\utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File ":D:\py\django\db\backends\utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File ":D:\py\django\db\backends\utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File ":D:\py\django\db\utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File ":D:\py\django\db\backends\utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File ":D:\py\django\db\backends\mysql\base.py", line 71, in execute
    return self.cursor.execute(query, args)
  File ":D:\py\MySQLdb\cursors.py", line 209, in execute
    res = self._query(query)
  File ":D:\py\MySQLdb\cursors.py", line 315, in _query
    db.query(q)
  File ":D:\py\MySQLdb\connections.py", line 239, in query
    _mysql.connection.query(self, query)
django.db.utils.ProgrammingError: (1146, "Table 'upsproject.jfwd].[t_dx_yjfs' doesn't exist")