python - 如何使用 Django 迁移重新创建已删除的表?

标签 python django postgresql django-models django-migrations

有两个模型 Groups 和 Students,只有一个表是 Groups of them,删除了 Students 表。

如何让Django重新创建被删除的表?如果我执行 makemigrations,它会打印“未检测到任何更改”。

在管理页面上,当我点击 Students 表时它抛出异常:

relation "students_students" does not exist

最佳答案

在 django 1.7 中你可以尝试:

1. Delete your migrations folder

2. In the database: DELETE FROM django_migrations WHERE app = 'app_name'.
   You could alternatively just truncate this table.

3. python manage.py makemigrations

4. python manage.py migrate --fake

如果您使用的是 django 1.9.5,这是此问题的 100% 解决方案:

1. Delete your migrations folder

2. In the database: DELETE FROM django_migrations WHERE app = 'app_name'.
   You could alternatively just truncate this table.

3. python manage.py makemigrations app_name

4. python manage.py migrate

这对我来说 100% 有效!

关于python - 如何使用 Django 迁移重新创建已删除的表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33259477/

相关文章:

postgresql - 如何将表行传递给 plpgsql 函数?

python - 如何在不安装的情况下使用烧杯?

python - 测量灰度图像的平滑度

sql - django 按日期时间中的日期排序/从日期时间中提取日期

python - Django,创建自定义 500/404 错误页面

postgresql - Postgres : Whether to use oid or byte array

python - 'not foo is none' 和 'foo is not none' 和有什么区别?

python - python中通过变量或不带括号调用函数

javascript - Django - 缓慢的 Ajax 响应似乎被延迟

postgresql - 我可以在数据库服务器上复制 Postgresql 大对象吗?