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

后端 未结 9 949
甜味超标
甜味超标 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:37

    In my case, GRANT PRIVILEGES solutions didn't work with Python 3.7.2, Django 2.1.7 and MySQL 5.6.23... I don't know why.

    So I decided to use SQLite as a TEST database...

    DATABASES = {
        'default': {
            'NAME': 'productiondb',
            'ENGINE': 'mysql.connector.django',   # 'django.db.backends.mysql'
            'USER': '',
            'PASSWORD': '',
            'HOST': 'localhost',
            'PORT': 3306,
            'OPTIONS': {
                'autocommit': True,
            },
            'TEST': {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
            },
        }
    }
    

    After that, TESTS car run without troubles:

    $ python manage.py test
    Creating test database for alias 'default'...
    System check identified no issues (0 silenced).
    
    Destroying test database for alias 'default'...
    ----------------------------------------------------------------------
    Ran 0 tests in 0.000s
    
    OK
    
    Process finished with exit code 0
    

提交回复
热议问题