diff --git a/nettacker/database/postgresql.py b/nettacker/database/postgresql.py index b8a1b505..d138e504 100644 --- a/nettacker/database/postgresql.py +++ b/nettacker/database/postgresql.py @@ -10,7 +10,6 @@ def postgres_create_database(): when using postgres database, this is the function that is used to create the database for the first time when you the nettacker run module. """ - try: engine = create_engine( "postgresql+psycopg2://{username}:{password}@{host}:{port}/{name}".format( @@ -21,15 +20,14 @@ def postgres_create_database(): except OperationalError: # if the database does not exist engine = create_engine( - "postgresql+psycopg2://{username}:{password}@{host}:{port}/{name}".format( + "postgresql+psycopg2://{username}:{password}@{host}:{port}/postgres".format( **Config.db.as_dict() ) ) conn = engine.connect() - conn.execute("commit") + conn = conn.execution_options(isolation_level="AUTOCOMMIT") conn.execute(text(f"CREATE DATABASE {Config.db.name}")) conn.close() - engine = create_engine( "postgresql+psycopg2://{username}:{password}@{host}:{port}/{name}".format( **Config.db.as_dict()