0

Im using mysql in my windows7 for a year and its working fine. I recently know about django and trying to catch up the tutorials. I'm having a problem to set up the setting.py and I think its on 'NAME' path.

DATABASES = 
   {
    'default': 
         {
          'ENGINE': 'django.db.backends.mysql',
          'NAME': os.path.join('C:/ProgramData/MySQL/MySQL Server 
                 5.7/Data/mysql', 'db.frm'),
          'USER': '***',
          'PASSWORD':'***'
          }
   }
Benyamin Jafari
  • 27,880
  • 26
  • 135
  • 150
Kaison
  • 31
  • 1
  • 4
  • That really isn't how MySQL works; it's not file-based like sqlite. You need the name of the database, not the file path. – Daniel Roseman Feb 18 '18 at 12:08
  • I created 'mfgtest' data base as a sample and located in this path. But still got same error C:\ProgramData\MySQL\MySQL Server 5.7\Data\mfgtest. – Kaison Feb 18 '18 at 12:11
  • No, I said you *don't* use a path. Why are you using a path? The value of NAME should be just "mfgtest". – Daniel Roseman Feb 18 '18 at 12:12
  • Thanks Daniel, I just put the database name after 'NAME' :' mfgtest 'and its working. Im not sure how it's able to locate the path. – Kaison Feb 18 '18 at 12:16
  • **There is no path**. I don't know why you think you need one. MySQL is a server, Django contacts that server and asks for the data. – Daniel Roseman Feb 18 '18 at 12:16
  • Thanks Daniel, That's clear enough.. – Kaison Feb 18 '18 at 12:23

2 Answers2

3

You just need to put the name of the database.

Example:

DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'DB NAME',
            'USER': 'USER NAME',
            'PASSWORD':'USER PW',
        }
    }

With that, it should work.

Jesux123
  • 173
  • 6
2

Try the following:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'PUT THE DATABASE NAME HERE',
        'USER': 'PUT THE USER NAME',
        'PASSWORD': 'PUT THE PASSWORD OF THE USERNAME ABOVE',
        'HOST': 'localhost or hostname/IP of the database server',
        'PORT': PORT NUMBER OF THE SERVER,
    }
}

You don't need to put the path of any database file, just specify the hostname, port, username and password - and Django will connect to it

Naim Ibrahim
  • 266
  • 1
  • 2
  • 10