kayeight
kayeight

Reputation: 43

Connecting to database in Vagrant via Django

I have a Django project set up that I want to run in a Vagrant vm. I was able to get the vm up and provisioned, and I have a MySQL database set up inside the vm that I'd like the Django app to connect to, but every time I attempt to run runserver I get this error:

django.db.utils.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")

Which seems like it's still trying to connect to my local MySQL instance.

My Vagrant networks settings are as follows:

config.vm.network :private_network, ip: "192.168.33.3"
config.vm.network :forwarded_port, guest: 3306, host: 8000

And the Django database settings:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'dbname',
        'USER': 'root',
        'PASSWORD': '',
        'PORT': 8000
    }
}

Tried the approach in this answer without success.

Upvotes: 1

Views: 902

Answers (1)

Tauseef
Tauseef

Reputation: 369

I was also having this issue. I have fixed this by editing settings.py provide the name hostname in the parameters of DATABASE. Finally the DATABASE parameters will be as below

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'djangodb', 'USER':'root', 'PASSWORD':'root', 'HOST':'127.0.0.1' } } It worked for me.

Upvotes: 1

Related Questions