I have 2 database
s of interest, the basic one and the development one:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| projectsdb |
| projectsdb_dev |
+--------------------+
3 rows in set (0.00 sec)
In my django file mysite/mysite/settings.py
, my databases are declared this way:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'projectsdb',
'USER': 'projectsdb',
'PASSWORD': 'notsecure',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
The allowed hosts is:
ALLOWED_HOSTS = ['xxx.xx.xxx.xx'] # I replaced it for the example
I start the server on the port 8006 which I use for developing:
$ python ./manage.py runserver xxx.xx.xxx.xx:8006
And here I modify the production database. I can switch to the dev database replacing the default database name:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'projectsdb_dev',
'USER': 'projectsdb',
'PASSWORD': 'notsecure',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
And it works fine, the server is interacting with the projectsdb_dev
database. However I would like to keep both databases available in the settings file and I saw tutorials setting it up this way:
DATABASES = {
'default': {},
'prod': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'projectsdb',
'USER': 'projectsdb',
'PASSWORD': 'notsecure',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
},
'dev': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'projectsdb_dev',
'USER': 'projectsdb',
'PASSWORD': 'notsecure',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
Now when I open the web page on xxx.xx.xxx.xx:8006, I get this error:
ImproperlyConfigured at /admin/
settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
I don't know if it's relevant but I also have this table:
mysql> select * from django_site;
+----+--------------------+----------------+
| id | domain | name |
+----+--------------------+----------------+
| 1 | example.com | example.com |
| 2 | xxx.xx.xxx.xx:8000 | projectsdb |
| 3 | xxx.xx.xxx.xx:8006 | projectsdb_dev |
+----+--------------------+----------------+
3 rows in set (0.00 sec)
How can I run the server specifying the correct database I want?