Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access model with other schema #222

Open
wgf4242 opened this issue Oct 13, 2020 · 0 comments
Open

Access model with other schema #222

wgf4242 opened this issue Oct 13, 2020 · 0 comments

Comments

@wgf4242
Copy link

wgf4242 commented Oct 13, 2020

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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant