嘿, 我已经创建了一个数据库。现在我更新了 UserProfile:
class UserProfile(models.Model):
user = models.ForeignKey(User, unique = True, related_name = 'user')
follows = models.ManyToManyField("self", related_name = 'follows') <-- NEW LINE
所以 python manage.py sqlall myapp
返回我:
[...]
CREATE TABLE "myapp_userprofile_follows" (
"id" integer NOT NULL PRIMARY KEY,
"from_userprofile_id" integer NOT NULL,
"to_userprofile_id" integer NOT NULL,
UNIQUE ("from_userprofile_id", "to_userprofile_id")
)
[...]
当我运行 python manage.py syncdb
时:
Creating tables ...
Installing custom SQL ...
Installing indexes ...
No fixtures found.
但是当我尝试向其中插入数据时,表并没有创建。为什么? (我在本地测试,使用 sqlite3)
最佳答案
manage.py syncdb
不会修改现有表来添加或删除字段。您将需要手动修改数据库,或使用类似 South 的工具创建自动数据库迁移(这是我强烈推荐的)
关于python - Django 不创建数据库表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6208636/