[Answered ]-How to connect to a database inside vagrant

2👍

Your network call should look like this:

config.vm.network :forwarded_port, guest: [db port x, e.g. 3306 for MySQL], host: [unused host port y]

In your Django configuration, leave the host empty (defaults to localhost) and specify the same port y from above. VirtualBox will forward your request to localhost:y to [guest]:x.

👤pauljm

0👍

I have tried this before, but it was quite a while ago, so this might not work. I was running a lucid32 box with postgres and django installed.

For database, you can just use the db name and the port that you installed it on. For me, installing vagrant did not give issues since my db was hosted on 127.0.0.1:5432, which was my windows config. I tried it and it worked with Vagrant as well.

You have a different database and different configurations, so this might not work, but its worth a shot.

Leave a comment