首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >django postgresql tests.py RuntimeWarning错误

django postgresql tests.py RuntimeWarning错误
EN

Stack Overflow用户
提问于 2019-05-27 08:15:47
回答 1查看 614关注 0票数 0

我有一个Django应用程序,可以在elephantsql.com在线添加和显示我的postgresql数据库中的内容。我的项目文件设置如下所示:

代码语言:javascript
复制
website/
    website/
    music/
    playlist/  
            __pycache__/
            migrations/
            static/
            templates/
            __init__.py
            admin.py
            apps.py
            models.py
            tests.py
            urls.py
            views.py
    .coverage
    db.sqlite3
    manage.py              

我的项目现在可以正常工作,当我运行服务器并转到/playlist/时,它可以正确地显示内容,并且可以很好地连接到我的postgresql数据库。

我的settings.py数据库对象如下所示:

代码语言:javascript
复制
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'kxvmghva',
        'USER': 'kxvmghva',
        'PASSWORD': '--an actual password---',
        'HOST': 'raja.db.elephantsql.com', 
        'PORT': '5432',
    }
}

现在,我正尝试在playlist/tests.py文件中编写测试用例,但是当我尝试运行这些测试时,我得到了错误。

我正在尝试运行的测试文件/playlist/tests.py

代码语言:javascript
复制
from django.test import TestCase
from .models import plays
from django.utils import timezone


class AnimalTestCase(TestCase):
    def setUp(self):
        print("setup")
        #Animal.objects.create(name="lion", sound="roar")
        #Animal.objects.create(name="cat", sound="meow")

    def test_animals_can_speak(self):
        """Animals that can speak are correctly identified"""
        print("test")
        #lion = Animal.objects.get(name="lion")
        #cat = Animal.objects.get(name="cat")
        #self.assertEqual(lion.speak(), 'The lion says "roar"')
        #self.assertEqual(cat.speak(), 'The cat says "meow"')

当我运行命令"python manage.py测试播放列表“时,我得到以下错误:

代码语言:javascript
复制
C:\Users\marti\Documents\kexp\website>python manage.py test playlist
Creating test database for alias 'default'...
C:\Python36-32\lib\site-packages\django\db\backends\postgresql\base.py:267: RuntimeWarning: Normally Django will use a connection to the 'postgres' database to avoid running initialization queries against the production database when it's not needed (for example, when running tests). Django was unable to create a connection to the 'postgres' database and will use the default database instead.
  RuntimeWarning
Got an error creating the test database: permission denied to create database

Type 'yes' if you would like to try deleting the test database 'test_kxvmghva', or 'no' to cancel:

如果我键入“yes”,则会导致以下错误:

代码语言:javascript
复制
Destroying old test database for alias 'default'...
Got an error recreating the test database: database "test_kxvmghva" does not exist

我一直试图通过在线搜索来解决这个错误,并尝试了一些方法,比如给我的用户'kxvmghva‘CREATEDB权限,以及在我的elephantsql db中运行下面这行:

将SCHEMA public中所有表的所有权限授予kxvmghva;

但是当我尝试为我的播放列表/应用程序运行tests.py文件时,我仍然收到这些错误。这是我第一次在django中为postgresql数据库设置测试用例,如果有任何帮助或指导,我将不胜感激。谢谢。

EN

回答 1

Stack Overflow用户

发布于 2019-05-27 09:53:22

我认为您用于数据库的计划是免费/共享的,在这种情况下,您没有创建其他数据库的权限。

这不是Django的问题,而是你正在使用的服务的限制。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56318323

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档