django test app error - Got an error creating the test database: permission denied to create database

后端 未结 9 932
甜味超标
甜味超标 2020-12-22 16:53

When I try to test any app with command (I noticed it when I tried to deploy myproject using fabric, which uses this command):

python manage.py test appname
         


        
9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-22 17:34

    If database is mysql then these two changes will get the things done.

    1.Open mysite/mysite/settings.py

    Your database settings should have an additional TEST block as shown with projectname_test.

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'myproject',
            'USER': 'chandan',
            'PASSWORD': 'root',
            'HOST': 'localhost',
            'PORT': '3306',
            'TEST': {
                'NAME': 'myproject_test',
            },
        }
    }
    

    2.Type the below command using mysql command prompt or mysql workbench to give all privilages to the user specified in settings.py

    GRANT ALL PRIVILEGES ON myproject_test.* TO 'chandan'@'localhost';
    

    Now you can run python manage.py test polls.

提交回复
热议问题