2016-05-17 49 views
1

我從pgAdmin III中刪除了我的postgresql數據庫(右鍵單擊數據庫/ mydatabase =>刪除/刪除)。操作失敗:數據庫不存在

現在我想重新啓動並進行第一次遷移,它應該創建數據庫,但是會出現錯誤:數據庫不存在。

到現在爲止我使用的是sqlite3,並且此過程可行。 我該怎麼辦?

完全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 
+1

HM,嘗試創建數據庫'手動possedimenti_database'。然後調用'manage.py migrate'。我希望就是這樣。 – Lucas03

回答

1

首先遷移不會創建數據庫,它需要現有的數據庫在其中創建表。

要從終端創建Postgres數據庫運行:

createdb -U postgres possedimenti_database 

您可能必須與您的數據庫用戶更換上面的命令Postgres的。

+1

我正在使用postgresql而不是sqlite3 – fabio

+1

我用命令更新了我的答案,從終端創建數據庫。 – ozren1983

1

檢查您的settings.py中的詳細信息爲您的數據庫。使用完全相同的細節(端口號,用戶,主機,密碼等)重新創建PostgreSQL數據庫。這裏試試這個現有的解決方案在這裏連結:

PostgreSQL - create a new DB through pgAdmin UI,以便通過pgAdmin的創建DB