settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': db,
'USER': user,
'PASSWORD': password,
'HOST': 'mysql01',
'PORT': '3306',
},
'otherdb': {
'ENGINE': 'django.db.backends.mysql',
'NAME': otherdb,
'USER': user,
'PASSWORD': password,
'HOST': 'mysql02'
'PORT': '3306',
}
}
application/models.py
from django.db import models
class <Name der Klasse>(models.Model):
class Meta:
db_table = '<Tabellenname>'
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length = 255)
application/views.py
from django.shortcuts import render
from .models import <Name der Klasse>
def index(request):
data = <Name der Klasse>.objects.db_manager("<DB-Name>").all()
params = { 'data': data }
return render(request, 'sample.html', params)
$ python3 ./manage.py makemigrations
$ python3 ./manage.py migrate
Recommended Posts