0

I'm brand new to Django (1st day) and setting up and environment on a MAC. I'm inside the environment created by pipenv and trying to execute python3 manage.py migrate. I get the error "Access denied for user 'user_name'@'localhost' to database 'db_name'".

I have no problems connecting to the database either inside or outside the pipenv environment using the mysql command line tool.

MAC version 12.3.1

MySQL version = 8.0.28

Python version = 3.9.12

Ideas?

TIA...

user2179204
  • 207
  • 2
  • 5

1 Answers1

0

In your settings.py file you should have something like:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', 
        'NAME': '<db_name>', # database name
        'USER': '<db_user>', # user with access to that database
        'PASSWORD': '<db_password>', # password for the user
        'HOST': 'localhost',   # if your database is hosted in another server then you should specify the host's IP
        'PORT': '3306', # default MySQL port
    }
}

Where <db_name>, <db_user>, <db_password> are the values that you use to connect to your MySQL server (the same ones that you are using to access MySQL via the command line tool). See the documentation https://docs.djangoproject.com/en/4.0/ref/settings/#databases for details. Also you can check this question and answers if you need an example with more options: Setting Django up to use MySQL

mtzd
  • 759
  • 4
  • 16