Forums

Can't access mysql and migrate not working on my models

Hello I'm a newcomer to this site and I was trying to access MySQL database, but it's still showing me this error Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) and ./manage.py migrate not applying the migrations to my models and I'm actually following the right settings in my app

  • 'ENGINE': 'django.db.backends.mysql', 'NAME': 'myusername$dbname', 'USER': 'myusername', 'PASSWORD': '', 'HOST': 'myusername.mysql.pythonanywhere-services.com', 'PORT': ''

And thanks in advanced

What is the command you are running to access your mysql database?

I'm using normal Bash with MySQL command, it worked but I want to be able to run ./manage.py migrate, which thrown an error

that sounds like the db name, or the user, or the password, or the host is wrong in your settings.py?

It sounds like it is trying to connect to a local mysql instead?

I faced same issues. To fix this all, For all newly created models do python manage.py makemigrations modelname https://docs.djangoproject.com/en/1.7/topics/migrations/#adding-migrations-to-apps

I am getting an error when I run this following command: python manage.py migrate (I did first 'python manage.py makemigrations, and I got 'no changes detected')

django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

However, my database engine info is in my .env file and it is 'django.db.backends.mysql'. In my virtualenv, the library 'mysqlclient' is installed.

In my settings py file, I have this configuration:

    DATABASES = {
    'default': {
        'ENGINE': os.getenv("DB_ENGINE"),
        'NAME': os.getenv("DB_NAME"),
        'USER': os.getenv("DB_USER"),
        'PASSWORD': os.getenv("DB_PASSWORD"),
        'HOST': os.getenv("DB_HOST"),
        'PORT': os.getenv("DB_PORT"),
    }
}

I think it doesn't load the env variables. That is the reason. But I couldn't fix it so far.

This link provided the solution. Thank you!

Glad to hear that!