Answer the question
In order to leave comments, you need to log in
Accessing the same database from different Django projects?
Hello! There are two projects:
Project-1 - PostgreSQL
Project-2 - SQLite
I want to make a request from Project-2 in PostgreSQL related to the first project.
To do this, Project-2 settings added additional database settings to the settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'front': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'site_db_v2',
'USER': 'alexandr',
'PASSWORD': '*********',
'HOST': '10.20.1.156',
'PORT': '5432',
}
}
class Meta:
app_label = 'exlorer'
db_table = 'exlorer_btcaddresse'
BtcAddresses.objects.using('front').all()
Internal Server Error: /
Traceback (most recent call last):
File "C:\PyProjects\Django_back\venv\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "exlorer_btcaddresse" does not exist
LINE 1: ...resse"."id", "exlorer_btcaddresse"."address" FROM "exlorer_b...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\PyProjects\Django_back\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\PyProjects\Django_back\venv\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\PyProjects\Django_back\venv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\PyProjects\Django_back\notification\monitor_events\views.py", line 11, in index
print(BtcAddresses.objects.using('front').all())
File "C:\PyProjects\Django_back\venv\lib\site-packages\django\db\models\query.py", line 252, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "C:\PyProjects\Django_back\venv\lib\site-packages\django\db\models\query.py", line 276, in __iter__
self._fetch_all()
File "C:\PyProjects\Django_back\venv\lib\site-packages\django\db\models\query.py", line 1261, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\PyProjects\Django_back\venv\lib\site-packages\django\db\models\query.py", line 57, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "C:\PyProjects\Django_back\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1151, in execute_sql
cursor.execute(sql, params)
File "C:\PyProjects\Django_back\venv\lib\site-packages\django\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "C:\PyProjects\Django_back\venv\lib\site-packages\django\db\backends\utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\PyProjects\Django_back\venv\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\PyProjects\Django_back\venv\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "C:\PyProjects\Django_back\venv\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\PyProjects\Django_back\venv\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "exlorer_btcaddresse" does not exist
LINE 1: ...resse"."id", "exlorer_btcaddresse"."address" FROM "exlorer_b...
^
[23/Apr/2020 00:19:32] "GET / HTTP/1.1" 500 129001
Answer the question
In order to leave comments, you need to log in
Well, in general, you have already succeeded, but most likely there is a typo in the table name. The error is directly related to postgres.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question