5

There are similar questions out there to this one, but I am not finding anything that is solving my issue.

I am working on a django project and made a database change and want to migrate the database change to production. So I run

python manage.py migrate

But I receive this error

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

From what I understand I must not have permission to run the migration, but I did try

grant all privileges on *.* to root@localhost identified by 'password' with grant option;

and different combinations thereof, but to no avail.

In my local_settings.py I have

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'root',
        'PASSWORD': 'password',
        'HOST': '127.0.0.1',
        'NAME': 'stratinvnet',
    },
}

I've tried to change 127.0.0.1 to localhost and that seems to make no difference. I have also tried to remove the password from the DATABASES object.

For what it's worth, here is my GRANTS table in mysql.

 GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*5FE8B16533FAE91D61522C9A6811F3F709147255' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION

and here is the user table.

 user       | host      | password                                  |
+------------+-----------+-------------------------------------------+
| root       | localhost | *5FE8B16533FAE91D61522C9A6811F3F709147255 |
| root       | 127.0.0.1 |                                           |
| root       | ::1       |                                           |
|            | localhost |                                           |
| root       | %         | *944B67F866A66B9DDD96024A97EBFDC886FC41F6 |
| phpmyadmin | localhost | *5FE8B16533FAE91D61522C9A6811F3F709147255 |
Matt Cremeens
  • 4,951
  • 7
  • 38
  • 67
  • But it says you're not using a password. – 101 Aug 20 '16 at 22:57
  • Exactly. So what am I doing wrong? Is there a way to grant permissions without identifying by a password? I tried to leave that part blank, but doing so didn't prevent the error. – Matt Cremeens Aug 20 '16 at 22:59
  • Do I need to run the migration and pass a password to manage.py? – Matt Cremeens Aug 20 '16 at 23:00
  • You should try use the root and password to login mysql like mysql -u root -p, to see if success or not. – Windsooon Aug 21 '16 at 02:48
  • What is `common.py` and how is it being imported into the rest of your project? – solarissmoke Aug 21 '16 at 03:12
  • @Aison can log in using root and password directly into mysql. That's no problem. – Matt Cremeens Aug 21 '16 at 11:32
  • @solarissmoke common.py is just for my local machine. It's the second database object that the server looks to. Perhaps I should just delete common.py from my question. – Matt Cremeens Aug 21 '16 at 11:33
  • There must be something overriding your `DATABASES` setting. What other apps do you have installed? – solarissmoke Aug 21 '16 at 11:59
  • @solarissmoke well, I tried to just migrate the specific table `python manage.py specific_table` but I got the same error. – Matt Cremeens Aug 21 '16 at 12:39
  • Also notice that I made some edits to provide more information I'm hoping will be helpful. – Matt Cremeens Aug 21 '16 at 12:49
  • You may try delete your app's migrations file then run makemigrations migrate again. – Windsooon Aug 21 '16 at 13:57
  • @Aison I think this is worth trying. I don't believe that my version has a `makemigrations` option, though. In that case do I just use `schemamigration`? – Matt Cremeens Aug 21 '16 at 13:58
  • What is your django version? Did you use South for migrations? – Windsooon Aug 21 '16 at 14:12
  • @Aison Yes. I have `south`, but the django version is just 1.5.5. – Matt Cremeens Aug 21 '16 at 14:13
  • I'm not familiar with south, but you could try use schemamigration yourapp --initial (backup the migration files first) – Windsooon Aug 21 '16 at 14:32
  • You know, @Aison, I see that the proper migration files have been copied over and I have this working on both my local machine and the beta environment. Just not production. I am going to try to re-run `schemamigration` with the `--auto --update` flag and see what happens. I appreciate you sticking with me. This has been a major problem for us. – Matt Cremeens Aug 21 '16 at 14:38
  • I almost feel like I'm getting somewhere. Doing what I said I would just above this comment gave me the message that the new fields had been added, but right after saying they had been added, I received the same error and going into mysql and doing a describe on the table showed that the new fields weren't there. :( – Matt Cremeens Aug 21 '16 at 14:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/121471/discussion-between-aison-and-matt-cremeens). – Windsooon Aug 21 '16 at 14:54

1 Answers1

0

seems like you use socks file for mysql, try replace:

'HOST': '127.0.0.1',

with this:

'HOST': '/var/lib/mysql/mysql.sock',  # 'HOST': 'localhost',
Rufat
  • 536
  • 1
  • 8
  • 25