fabio
fabio

Reputation: 1365

Operationalerror: database don't exist

I deleted my postgresql database from pgAdmin III (right click on databases/mydatabase => delete/drop).

Now I want start anew and make the first migration that should create the database but instead it give an error: database don't exist.

Until now I was using sqlite3 and this procedure worked. What I should do?

Full traceback:

(myvenv) c:\Python34\Scripts\possedimenti\sitopossedimenti>manage.py migrate
Traceback (most recent call last):
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 199, in ensure_connection
    self.connect()
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 171, in connect
    self.connection = self.get_new_connection(conn_params)
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\postgresql\base.py", line 175, in get_new_connection
    connection = Database.connect(**conn_params)
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\psycopg2\__ini
t__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.OperationalError: FATALE:  il database "possedimenti_database" non esis
te


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Python34\Scripts\possedimenti\sitopossedimenti\manage.py", line 10, i
n <module>
    execute_from_command_line(sys.argv)
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\core\ma
nagement\__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\core\ma
nagement\__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\core\ma
nagement\base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\core\ma
nagement\base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\core\ma
nagement\commands\migrate.py", line 89, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\migr
ations\executor.py", line 20, in __init__
    self.loader = MigrationLoader(self.connection)
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\migr
ations\loader.py", line 49, in __init__
    self.build_graph()
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\migr
ations\loader.py", line 176, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\migr
ations\recorder.py", line 65, in applied_migrations
    self.ensure_schema()
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\migr
ations\recorder.py", line 52, in ensure_schema
    if self.Migration._meta.db_table in self.connection.introspection.table_name
s(self.connection.cursor()):
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 231, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 204, in _cursor
    self.ensure_connection()
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 199, in ensure_connection
    self.connect()
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\util
s.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\utils\s
ix.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 199, in ensure_connection
    self.connect()
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 171, in connect
    self.connection = self.get_new_connection(conn_params)
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\postgresql\base.py", line 175, in get_new_connection
    connection = Database.connect(**conn_params)
  File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\psycopg2\__ini
t__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: FATALE:  il database "possedimenti_database" n
on esiste

Upvotes: 1

Views: 67

Answers (2)

deadlock
deadlock

Reputation: 7310

check the details in your settings.py for your DB. Recreate the PostgreSQL database using those exact same details (port number, user, host, password etc). Try this existing solution here link here:

PostgreSQL - create a new DB through pgAdmin UI in order to create the DB via pgAdmin

Upvotes: 1

ozren1983
ozren1983

Reputation: 1951

First migration doesn't create the database, it needs existing database to create tables in it.

To create postgres database run from your terminal:

createdb -U postgres possedimenti_database

You might have to replace postgres in above command with your database user.

Upvotes: 1

Related Questions