python - Django 不创建数据库表

标签 python django

嘿, 我已经创建了一个数据库。现在我更新了 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/

相关文章:

javascript - 为什么 Javascript 不能给出比 python 更准确的科学计算结果

python - Django 投票应用程序 : AttributeError: 'Choice' object has no attribute 'question_text'

javascript - 向数据表添加超链接时遇到问题

python - 值错误 : "needs to have a value for field "id"before this many-to-many relationship can be used"

python - 退出 Python 调试器 ipdb

python - 如何从 pandas 的列子集中选择行子集

python - 在每个元素上使用条件的 Numpy 过滤器

python - 如何使用 Python 创建输入框?

Django order_by 多对多关系

Django slugs 不唯一且 unique=True