我定义了两个模型:
class Server(models.Model):
owners = models.ManyToManyField('Person')
class Person(models.Model):
name = models.CharField(max_length=50)
admin.site.register(Server)
admin.site.register(Person)
之后我什至检查了 sql,只是为了好玩:
BEGIN;
CREATE TABLE "servers_server_owners" (
"id" integer NOT NULL PRIMARY KEY,
"server_id" integer NOT NULL,
"person_id" integer NOT NULL,
UNIQUE ("server_id", "person_id")
)
;
CREATE TABLE "servers_server" (
"id" integer NOT NULL PRIMARY KEY,
"name" varchar(50) NOT NULL,
"port" integer unsigned NOT NULL,
"state" integer NOT NULL
)
;
CREATE TABLE "servers_person" (
"id" integer NOT NULL PRIMARY KEY,
"name" varchar(50) NOT NULL
)
;
COMMIT;
它甚至说CREATE TABLE "servers_server_owners"
我跑去syncdb
将新模型安装到数据库中。我去管理界面定义了一些要玩的对象,但出现以下错误:
DatabaseError at /admin/servers/server/1/
no such table: servers_server_owners
我关闭了开发服务器,syncdb
再次运行,启动服务器:仍然是同样的问题。为什么它找不到表,即使它只是告诉我它创建了 id?