我正在使用 2 个数据库,1 个不是由 Django 管理的外部数据库,另一个是内部数据库。
这是现在在模型和管理站点中工作的外部数据库:
class Client(models.Model):# IMPORT FROM MYSQL
code = models.CharField(max_length=3, primary_key=True)
name = models.CharField(max_length=250)
region_id = models.IntegerField(db_column="RegionId")
class Meta:
managed = False
db_table = 'client'
这是 Django 在另一个数据库上管理的:
class ClientJuno(models.Model):
LABORATORIES = (('SCR','SCREENS'), ('DVR','DVMR'),)
client = models.ForeignKey(Client, on_delete=models.SET_NULL, null=True)
profiles = models.ManyToManyField(JunoProfile)
laboratory = models.CharField(max_length=20, choices=LABORATORIES)
在打开最后一个模型时查看错误。找不到表客户端。
OperationalError at /admin/settings/clientjules/
no such table: client
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/settings/clientjules/
Django Version: 2.2.11
Exception Type: OperationalError
Exception Value:
no such table: client
Exception Location: /usr/local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py in execute, line 383
Python Executable: /usr/local/bin/python
Python Version: 3.6.10
Python Path:
['/app/mmike',
'/usr/local/lib/python36.zip',
'/usr/local/lib/python3.6',
'/usr/local/lib/python3.6/lib-dynload',
'/usr/local/lib/python3.6/site-packages']
Server time: Mon, 20 Apr 2020 08:11:26 +0000