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

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

问题描述

有两个模型组和学生,其中只有一个表用于组,学生表被删除。

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

如何让Django重新创建?如果执行 makemigrations ,它将显示未检测到更改。

How to maje Django create it again? 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天全站免登陆