Forums

Unknown MySQL server host

I tried connecting my database to my django app 1.10 and i followed the directions on how to set it up and connect it to my app but when i go to my bash console in my app directory and run python manage.py inspectdb or anything that has to do with the database i get

django.db.utils.OperationalError: (2005, "Unknown MySQL server host '<MovieHd.mysql.pythonanywhereservices.com>' (0)")

I have my setting file as so

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': '<your_username>$<your_database_name>',
    'USER': '<your_username>',
    'PASSWORD': '<your_mysql_password>',
    'HOST': '<MovieHd.mysql.pythonanywhere-services.com>',
}}

and i did replace the other fields with my username, database name, and password. What should i check and do to resolve this problem

That's very strange. What happens if you try to start a MySQL console from the "Databases" tab?

The consol connects to the database

Ah, got it -- your settings file isn't exactly what's being run by the code that generated the error message you pasted. If you look at the error message, it says you're trying to connect to MovieHd.mysql.pythonanywhereservices.com -- it's missing the "-" between pythonanywhere and services. If you change your settings file so that it uses the correct hostname, it will work.

After changing the settings to adding a "-" i still got

(2005, "Unknown MySQL server host '<MovieHd.mysql.pythonanywhere-services.com>' (0)")

Just to confirm- is this an error message that you are seeing from your webapp error logs?

no it is from the console when i try to migrate my models to the database

You have '<' and '>' around your host name. They are not part of a host name. Remove them. You may be making the same mistake with the other fields in your DATABASES dictionary.

glenn is 100% correct

hello

I am getting the following error when I try to migrate my models to the databases:

(1045, "Access denied for user '*'@'10.0.0.98' (using password: YES)")

code below is attached without filling out the fields:

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': '<*>$dtrain_db', 'USER':'*', 'PASSWORD': '<**>', 'HOST': 'xxxxxx.mysql.pythonanywhere-services.com', } }

Do you have the < and > around your username and password?

Not any more. So I was able to fix that , but now I have another one: Its a 1146 error.When I try to go to my URL I get the following:

ProgrammingError at /admin

(1146, "Table 'collins73$dtrain_db.pages_page' doesn't exist") There are no brackets.. Not sure how to fix this error...

Code in my settings.py: ENGINE': 'django.db.backends.mysql', 'HOST': 'collins73.mysql.pythonanywhere-services.com', 'NAME': 'collins73$dtrain_db', 'OPTIONS': {}, 'PASSWORD': '****', 'PORT': '',

Not any more. So I was able to fix that , but now I have another one: Its a 1146 error.When I try to go to my URL I get the following:

ProgrammingError at /admin

(1146, "Table 'collins73$dtrain_db.pages_page' doesn't exist") There are no brackets.. Not sure how to fix this error...

Code in my settings.py: ENGINE': 'django.db.backends.mysql', 'HOST': 'collins73.mysql.pythonanywhere-services.com', 'NAME': 'collins73$dtrain_db', 'OPTIONS': {}, 'PASSWORD': '****', 'PORT': '',

Not any more. So I was able to fix that , but now I have another one: Its a 1146 error.When I try to go to my URL I get the following:

ProgrammingError at /admin

(1146, "Table 'collins73$dtrain_db.pages_page' doesn't exist") There are no brackets.. Not sure how to fix this error...

Code in my settings.py: ENGINE': 'django.db.backends.mysql', 'HOST': 'collins73.mysql.pythonanywhere-services.com', 'NAME': 'collins73$dtrain_db', 'OPTIONS': {}, 'PASSWORD': '****', 'PORT': '',

Did you create that table? (by running manage.py create migrations and migrate)

Yes I ran through the migrations commands so the tables should have already been created. It looks like I will need to recreate the table. again. what do you recommend? Is there a specific command other than the following:

python manage.py migrate

thanks.

Why "other than migrate". That's the way Django manages its databases.