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

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

    If you are using docker-compose what worked for me was the following:

    ALTER ROLE username CREATEDB;
    GRANT ALL PRIVILEGES ON test_database_name.* TO 'username';
    

    or

    ALTER ROLE username CREATEDB;
    GRANT ALL PRIVILEGES ON *.* TO 'username'@'%';
    

    My settings looks like this:

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'database_name',
            'USER': 'username',
            'PASSWORD': 'password',
            'HOST': 'db',
            'PORT': '3306',
        }
    }
    

    and my docker-compose.yml looks as follows:

    version: '3'
    services:
      web:
          build: .
          command: './wait_for_db_and_start_server.sh'
          env_file: env_web
          working_dir: /project_name
          links:
            - db
          volumes:
            - .:/volume_name
          ports:
            - "8000:8000"
          depends_on:
            - db
      db:
        image: mysql:5.7
        restart: always
        env_file: env_db
        working_dir: /db
        volumes:
          - ./Dump.sql:/db/Dump.sql
        ports:
          - "3306:3306"
    

提交回复
热议问题