# 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' *when I push run this in Liunx server,it still use the default config.* 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)") -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cc9ae2e2-1771-4f34-8fd3-fe9838691172%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.