Operational error: FATAL: django database does not exist

I am a db mannequin and I am trying to configure PostgreSQL for my django project. For this I also use psycopg2. However, databases are complex. Personally, I would like to see ALL my DATABASES and USER / SETTINGS / INFO in one place. Therefore, I knew what I needed to connect and how (I still work locally, so there are no security issues?).

However, it seems that I do not have "rights" to create this database, although I connect to the standard "admin" -user "postgres". With the password that I entered for the installation ("Justdoit_90").

Django-project (settings.py):

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'django', 'USER': 'postgres', 'PASSWORD': 'Justdoit_90', 'HOST': '127.0.0.1', 'PORT': '5432', } } 

CMD -> python manage.py shell (after importing django.db connection)

 >>> cursor = connection.cursor() Traceback (most recent call last): File "<console>", line 1, in <module> File "C:\Python27\lib\site-packages\django\db\backends\__init__.py", line 165, in cursor cursor = self.make_debug_cursor(self._cursor()) File "C:\Python27\lib\site-packages\django\db\backends\__init__.py", line 138, in _cursor self.ensure_connection() File "C:\Python27\lib\site-packages\django\db\backends\__init__.py", line 133, in ensure_connection self.connect() File "C:\Python27\lib\site-packages\django\db\utils.py", line 94, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) File "C:\Python27\lib\site-packages\django\db\backends\__init__.py", line 133, in ensure_connection self.connect() File "C:\Python27\lib\site-packages\django\db\backends\__init__.py", line 122, in connect self.connection = self.get_new_connection(conn_params) File "C:\Python27\lib\site-packages\django\db\backends\postgresql_psycopg2\base.py", line 134, in get_new_connection return Database.connect(**conn_params) File "C:\Python27\lib\site-packages\psycopg2-2.5.4-py2.7-win32.egg\psycopg2\__init__.py", line 164, in connect conn = _connect(dsn, connection_factory=connection_factory, async=async) OperationalError: FATAL: database "django" does not exist 

Did I do something wrong in the installation? Can i fix this? Should I reinstall everything? How can i do this? Databases confuse me: P

+6
source share
3 answers

PostgreSQL does not automatically create databases on the first connection. You must create a database before you can use it.

Connect to PostgreSQL (usually an administration database called "postgres") through PgAdmin-III or the psql command-line client and create the django database. From PgAdmin-III you can do this through the menu; from psql you use the CREATE DATABASE SQL CREATE DATABASE .

See also Creating a PostgreSQL Database in a Guide and this tutorial, which I found in a 5 second Google search, that doesn't look completely wrong .

What would I do, connect using psql (you can find it in the Start menu) as the user "postgres" with the password set during installation, and then:

 CREATE USER django WITH PASSWORD 'somepassword'; CREATE DATABASE django WITH OWNER django ENCODING 'utf-8'; 
+11
source

All you have to do is create a database called django in your postgresql. By default, the postgres user will have privilege in the django database, and the password will be the password for postgres users.

0
source

Source: https://habr.com/ru/post/976745/


All Articles