【发布时间】:2012-04-02 21:15:36
【问题描述】:
我在一个简单的 django 项目中设置了几个模型。当我跑步时
python manage.py sql fivefives
当我运行 syncdb 或验证时,我得到了很多好看的 sql,我得到 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.
}
}
以前有人想出过类似的东西吗?只需将所有文件复制到我朋友的计算机上并进行同步,一切都很好。
【问题讨论】:
-
糟糕的时刻。我使用的'postgres'默认用户显然缺少一些东西。我刚换成了我的 mac 的超级用户 dave,运行了 syncdb,这一切都发生了,现在可以正常工作了。
-
答案已经发布。但有一个提示:使用南。它处理模式迁移并且是事实上的标准。
-
我一定会去看看——在我创建了一个字段 null=True 之后,我确实需要它。谢谢
标签: django postgresql