我在一個簡單的django項目中設置了幾個模型。當我運行Django查詢在postgres中消失
python manage.py sql fivefives
我得到好看的SQL負載,當我運行執行syncdb或驗證我得到0個錯誤。
BEGIN;
CREATE TABLE "fivefives_player" (
"id" serial NOT NULL PRIMARY KEY,
"username" varchar(200) NOT NULL,
"colour" varchar(7) NOT NULL,
"remaining_dice" integer NOT NULL
)
;
CREATE TABLE "fivefives_game_player_list" (
"id" serial NOT NULL PRIMARY KEY,
"game_id" integer NOT NULL,
"player_id" integer NOT NULL REFERENCES "fivefives_player" ("id") DEFERRABLE INITIALLY DEFERRED,
UNIQUE ("game_id", "player_id")
)
;
CREATE TABLE "fivefives_game" (
"id" serial NOT NULL PRIMARY KEY,
"time" timestamp with time zone NOT NULL
)
;
ALTER TABLE "fivefives_game_player_list" ADD CONSTRAINT "game_id_refs_id_c39af54" FOREIGN KEY ("game_id") REFERENCES "fivefives_game" ("id") DEFERRABLE INITIALLY DEFERRED;
CREATE TABLE "fivefives_round_player_list" (
"id" serial NOT NULL PRIMARY KEY,
"round_id" integer NOT NULL,
"player_id" integer NOT NULL REFERENCES "fivefives_player" ("id") DEFERRABLE INITIALLY DEFERRED,
UNIQUE ("round_id", "player_id")
)
; ... it continues like this...
但是,一旦我跳進管理員,表格就不存在了。登錄到postgres我看到表格甚至沒有被創建。
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'perudodb', # Or path to database file if using sqlite3.
'USER': 'postgres', # Not used with sqlite3.
'PASSWORD': 'postgres', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
任何人都想出了這樣的事情之前?只需將所有文件複製到我的好友計算機上並syncdb'd,這一切都很好。
Urghhh時刻。我使用的'postgres'默認用戶顯然缺乏一些東西。我剛剛變成了dave,我的mac的超級用戶,運行syncdb,這一切都發生了,現在正在工作。 – Djave 2012-04-02 21:20:31
答案已經發布。但有一個提示:使用南方。它處理模式遷移並且是事實上的標準。 – guettli 2012-04-03 07:21:09
我一定會檢查出來的 - 在創建完成後需要完成這個操作才能創建一個字段爲null = True。謝謝 – Djave 2012-04-03 18:46:54