# setting.py
DATABASES = {
'remote': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '10.0.3.57',
'NAME': 'fast_last',
'USER': 'faster',
'PASSWORD': 'mypassword',
'TEST': {
'MIRROR': 'default',
}
},
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'fast',
'USER': 'root',
'PASSWORD': 'root',
'TEST': {
'NAME': 'test_fast_last',
}
}
}
DATABASE_ROUTERS = ['FasterRunner.database.AutoChoiceDataBase']
# database.py
import platform
class AutoChoiceDataBase:
run_system = platform.system()
is_windows = run_system == 'Windows'
def db_for_read(self, model, **hints):
if self.is_windows:
return 'default'
else:
return 'remote'
def db_for_write(self, model, **hints):
if self.is_windows:
return 'default'
else:
return 'remote'
python manage.py runserver 0.0.0.0:8000
File "/home/faster/.virtualenvs/fasterenv/lib/python3.6/site-packages/MySQLdb/connections.py", line 204, in __init__ super(Connection, self).__init__(*args, **kwargs2)django.db.utils.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")