Здравствуйте! Есть два проекта:
Проект-1 - PostgreSQL
Проект-2 - SQLite
Хочу из Проект-2 сделать запрос в PostgreSQL относящуюся к первому проекту.
Для этого в сеттингс Проект-2 добавил настройки дополнительной БД:
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',
}
}
В Проект-2 добавил модель, как в первом проекте, только переопределил названия:
class Meta:
app_label = 'exlorer'
db_table = 'exlorer_btcaddresse'
На Проекте-2 никаких миграций по отношению к дополнительной базе('front' - основная для Проект-1) не проводил.
В итоге при запросе
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
Подскажите пожалуйста, как сделать запрос к БД от Проекта-1?