django重新创建删除的表 [英] django recreate dropped table

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

问题描述

我在更改模型时手动放置了一个表,这是我犯了一个非常严重的错误.所以无论如何...我该如何重新创建它?我已经尝试过了:

I dropped a table manually cause while changing the model I made a very bad mistake. So anyway ... how can I recreate it ? I have tried :

- Delete the migrate folder of that app
- delete from django_migrations where app='main'
- makemigrations main
- migrate main

但是它停在第一张桌子上.在那里:-(并且在这种情况下,我的表message不会重新创建.在0001_initial.py中,我的表具有正确的条目

But it stops at the first table. Which is there :-( and my Table message in that case is not recreated. In 0001_initial.py I have the correct entry for my table

migrations.CreateModel(
        name='Message',
        fields=[
            ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
            ('created_at', models.DateTimeField(auto_now_add=True)),
            ('updated_at', models.DateTimeField(auto_now=True)),
            ('unread', models.BooleanField(default=True)),
            ('subject', models.CharField(max_length=120)),
            ('freetext', models.TextField(null=True)),
            ('from_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='from_user', to=settings.AUTH_USER_MODEL)),
            ('to_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='to_user', to=settings.AUTH_USER_MODEL)),
        ],
    ),

有没有办法手动启动此操作?

Is there way to start this manually ?

推荐答案

下次回滚时:

  1. 进入应用程序中的迁移文件夹.

  1. Go into the migrations folder in your app.

查找您想返回到的迁移文件. (例如0012_post_category.py)

Look for the migration file where you would like to go back to. (for example 0012_post_category.py)

在终端中输入:./manage.py迁移yourAppName 0012(这只是一个示例数字),然后按Enter键

go in the terminal write: ./manage.py migrate yourAppName 0012 (this is just an example number) and hit enter

如果一切顺利.删除迁移文件夹中此编号之后的其他迁移.

if everything goes well. Delete the other migrations which came after this number in your migrations folder.

不要只删除迁移!希望有帮助.

Do not just delete migrations! Hope that helps.

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

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