我在一个简单的django项目中设置了一些模型。我跑的时候
python manage.py sql fivefives
当我运行syncdb或验证我得到0错误时,我得到了很多漂亮的sql。
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.
}
}
之前有人想出过这样的事吗?只是将所有文件复制到我的朋友计算机上并同步,这一切都很有效。
答案 0 :(得分:0)
manage.py sql
实际上并不运行SQL,它只是打印它。
答案 1 :(得分:0)
要实际创建表格,您需要manage.py syncdb
。