如何使用 Django Migrations 重新创建已删除的表? [英] How to recreate a deleted table with Django Migrations?

查看:35
本文介绍了如何使用 Django Migrations 重新创建已删除的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个模型Groups和Students,其中Groups只有一张表,Students表被删除了.

There are two models Groups and Students and only one table for Groups of them, the Students table was deleted.

如何让 Django 重新创建已删除的表?如果我执行 makemigrations,它会打印未检测到更改".

How to make Django recreate the deleted table? If I do makemigrations it prints "No changes detected".

在管理页面上,当我单击学生表时,它会引发异常:

On admin page when I click on the Students table it throws an exception:

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% 有效!

This works 100% for me!

这篇关于如何使用 Django Migrations 重新创建已删除的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆