Django db utils programmingerror ошибка тип hstore не существует

I am using postgres with my django app and I had manually created the hstore extension in the database. But, when I run tests it tries to create a new database and fails when the hstore extension is not found.

I am getting the following errors:

django.db.utils.ProgrammingError: hstore type not found in the database. please install it from your 'contrib/hstore.sql' file

I have update my migrations as per this post and it’s as follows:

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
from django.conf import settings
from django.contrib.postgres.operations import HStoreExtension
import django.contrib.postgres.fields
import django.contrib.postgres.fields.hstore


class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        HStoreExtension(),
        migrations.CreateModel(
        name='AppUser',
        fields=[
            ('id', models.AutoField(serialize=False, verbose_name='ID', primary_key=True, auto_created=True)),
            ('created_date', models.DateTimeField(auto_now_add=True)),
            ('modified_date', models.DateTimeField(auto_now=True)),
            ('lock', models.BooleanField(default=False)),
            ('username', models.CharField(max_length=100)),
            ('email', models.EmailField(max_length=150)),
            ('social_data', django.contrib.postgres.fields.hstore.HStoreField(blank=True, default='')),
            ('phone_number', models.CharField(max_length=15)),
            ('photo', models.URLField(blank=True)),
            ('gender', models.TextField(max_length=6)),
            ('badges', django.contrib.postgres.fields.ArrayField(size=None, base_field=models.CharField(max_length=30))),
        ],
        options={
            'abstract': False,
        },
    ),
    ]

Hi guys so I know this question has been asked many times but the solution that have been provided doesn’t seem to fix the source of my problem.

Based on what I’ve seen the solution is to run create extension hstore.

However, I get the error django.db.utils.ProgrammingError: type "hstore" does not exist when I’m trying to run a django test, ie python manage.py test test_function

I’m not familiar with django tests but from what I’m seeing with the codebase I am working with is that the django test is creating a test database when I run the django test command.

When I checkout what extensions are available with the test database with dx I see that it does not have hstore. If I run create extension hstore then the hstore extension gets created. Problem is that whenever I rerun the django test, python manage.py test test_function it tells me the test database already exists and I need to delete it first otherwise the command exits. By deleting the database the extension that just got added also gets removed thus when I run python manage.py test test_function again I end up with the same error.

How do I get rid of the error? Thank you.

#24645

closed


Cleanup/optimization


(fixed)

django.db.utils.ProgrammingError: type «hstore» does not exist

Reported by: Owned by: nobody
Component: Documentation Version: 1.8
Severity: Normal Keywords: type «hstore» does not exist
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

I’m using new database field ‘HStoreField’ in my project, my psycopg2 is 2.6 and postgresql is 9.4.11 with postgres.app. When I using python manage.py migrate, it raise a ‘django.db.utils.ProgrammingError’ which says django.db.utils.ProgrammingError: type «hstore» does not exist. I have added ‘django.contrib.postgres’ in my settings.INSTALLED_APPS. I have used ArrayField() with base_field ‘CharField’ is ok. Only when I using HStoreField, there is error.

I am trying to install the hstore extension before running django tests. For that, I have overridden the default DiscoverRunner‘s setup_databases method.

However, the extension is not installed & the tests show this error
django.db.utils.ProgrammingError: type "hstore" does not exist

TEST_RUNNER = 'project.tests.CustomDiscovererRunner'
from django.db import DEFAULT_DB_ALIAS, connections
from django.test.runner import DiscoverRunner

class CustomDiscovererRunner(DiscoverRunner):
    def setup_databases(self, **kwargs):

        result = super().setup_databases(**kwargs)

        connection = connections[DEFAULT_DB_ALIAS]
        cursor = connection.cursor()
        cursor.execute('CREATE EXTENSION IF NOT EXISTS HSTORE')
        
        return result

python migrate hstore[] does not exist

Today when doing database migration — ie python3manage.py The migration has a problem:

django.db.utils.ProgrammingError: type "hstore[]" does not exist
#LINE 1: ...t" ("id" serial NOT NULL PRIMARY KEY, "viewports" hstore[] N...

Solution

python3 manage.py dbshell
create extension hstore

Intelligent Recommendation

PostgreSQL hstore

2019 Unicorn Enterprise Heavy Glour Recruitment Python Engineer Standard >>> I have repeatedly used the usage of the EXT field, simply mention that PostgreSQL’s powerful support for this Key …

Why does it take so long to migrate to Python 3?

Author | Vicki Boykis Translator | Wang Wengang Planning | Xiaozhi In Pycon 2014, the inventor of Python Guido van Rossum said: «Now is the time to enter Python 3!» — He told the audience th…

More Recommendation

  • Related Posts
  • os.path.walk in python 3 does not exist in the
  • Python If the folder does not exist, new
  • Python is empty if the folder does not exist
  • Learning python records Python3 does not exist raw_input()
  • Python judged directory exists, does not exist, create
  • Python os.path.exists (file_name) to write the file does not exist
  • Python judgment file (folder) does not exist, there is no creation
  • Create a folder when the Python folder does not exist
  • Python saves files, create if the directory does not exist,
  • Python determines that the folder does not exist, create a folder
  • Popular Posts
  • Advanced management of system logs for linux entry (journal service, chronyd service and use of timedatectl)
  • Learn INI file
  • Will stdout and stderr affect each other?
  • JavaScript and regular expressions — position matching
  • Bean management (combination of annotations, xml and annotations)
  • Union search set of extended domain (2)
  • Home of Black Monkey: Mac OS 10.12.0 install VMware Tools
  • The most efficient language, intuitive experience of the bottom layer of the computer — the first day of understanding assembly language
  • SpringBoot cross domain
  • Shandong University Innovation Training 2020/6/18
  • Recommended Posts
  • PIXI Renderer Learning Notes (1)
  • Spring JDBC framework (7)
  • How to simplify Python Programs | Command Line Parameters | and | Profile |
  • C ++ implementations interest due on revolving credit accounts, total amount due, minimum payment.
  • When using the UnitTest framework to generate a test report, the code execution is complete, not generated in the specified directory.
  • Interface Automation notes -httpget and httppost Code
  • Extend the Ant Design Pro button Component color scheme
  • Unity_Shader Advanced Article_16_Unity Shader Getting Started Essentials_Reduce Computational Complexity
  • Np.tile() function parsing
  • vue-cli3+Electron
  • Related Tags
  • Pythonscientific researchpythonLinuxoswindowsproblem solvedHands in deep learning pytorchPython learningPython learning materials

Понравилась статья? Поделить с друзьями:
  • Dishonored exe ошибка при запуске приложения 0xc0000906
  • Diacont глюкометр ошибка e u
  • Df885 ошибка рено лагуна 3
  • Df2 ошибка зарядное устройство hawker
  • Df150 ошибка рено логан 2