2014-01-15 131 views
0

我正在使用python/python 3在win7上進行開發,在python/django上使用便攜式環境。我決定嘗試將postgresql添加到我的項目(「rob1」)中,該項目位於我的virtualenv「R1」中,並且我使用的是http://sourceforge.net/projects/pgsqlportable/django south:「由於目標機器主動拒絕,所以無法建立連接。」

我正在首次與South合作。

我改變了我的模特,救了我的工作,跑到:

$ ./manage.py schemamigration MYAPP--auto 
- Deleted field date on getPost.Url 
Created 0005_auto__del_field_url_date.py. You can now apply this migration with: ./manage.py migrate MYAPP 

但是當我運行:

./manage.py migrate MYAPP 

我得到一個長回溯結尾:

django.db.utils.ProgrammingError: no existe la relación «south_migrationhistory» 
LINE 1: ...gration", "south_migrationhistory"."applied" FROM "south_mig... 

我postgres控制檯然後顯示:

ERROR: no existe la relación «south_migrationhistory» en carácter 154 
SENTENCIA: SELECT "south_migrationhistory"."id", "south_migrationhistory"."app_ 
name", "south_migrationhistory"."migration", "south_migrationhistory"."applied" 
FROM "south_migrationhistory" WHERE "south_migrationhistory"."applied" IS NOT NU 
LL ORDER BY "south_migrationhistory"."applied" ASC 
LOG: no se pudo recibir datos del cliente: No connection could be made because 
the target machine actively refused it. 

這些更改未反映在postgres表中。我怎樣才能解決這個問題?

編輯:

$ ./manage.py syncdb   
Syncing... 
Creating tables ... 
Creating table south_migrationhistory 
Installing custom SQL ... 
Installing indexes ... 
Installed 0 object(s) from 0 fixture(s)  

Synced: 
> django.contrib.admin 
> django.contrib.auth 
> django.contrib.contenttypes 
> django.contrib.sessions 
> django.contrib.messages 
> django.contrib.staticfiles 
> south  

Not synced (use migrations): 
- getPost 
(use ./manage.py migrate to migrate these) 
(r1)  

$ ./manage.py migrate getPost 

Running migrations for getPost: 
- Migrating forwards to 0005_auto__del_field_url_date. 
> getPost:0001_initial 
FATAL ERROR - The following SQL query failed: CREATE TABLE "getPost_poll" ("id" serial NOT NULL PRIMARY KEY, "question" varchar(200) NOT NULL, "pub_date" timestamp with 
time zone NOT NULL) 
The error was: la relación «getPost_poll» ya existe  

Error in migration: getPost:0001_initial 

我可以看到你讓我拉近了許多。任何進一步的建議?

回答

1

south_migrationhistory似乎不存在。在使用南遷移之前,您需要運行一次manage.py syncdb

south_migrationhistory對於每個應用程序,已存在哪些遷移。如果您將現有應用轉換爲南,則初始遷移應與當前架構狀態匹配,例如,在創建初始遷移之前,您不應該進行任何模型更改。然後,使south_migrationhistory表匹配模式狀態下,可以「假申請」初始遷移:

manage.py migrate appname 0001 --fake 

,將創建在south_migrationhistory表中的初始遷移記錄而不實際試圖做任何架構變化。現在,您可以應用其餘的遷移:

manage.py migrate appname 
+0

請參閱編輯 – user61629

+0

我猜'ya existe'表示已存在?在創建遷移之前,您是否爲'getPost'執行'syncdb'?這樣,表格就會存在,但南方'認爲'它們沒有。如果最初的遷移0001匹配您當前的數據庫狀態,您可以執行'manage.py migrate getPost 0001 --fake'然後'manage.py migrate' – sk1p

+0

再次感謝sk1p。你有它的工作!我在004遷移中遇到遷移錯誤。但至少它已經達到了這一點。最好的問候 - 比爾 – user61629

相關問題