python - 在运行 'migrate' 命令之前删除 Django 迁移文件?

标签 python django

假设我有这个模型,它已经实现了一些先前的迁移:

from django.db import models
from django.contrib.auth.models import User
from PIL import Image

class Profile(models.Model):
    account = models.OneToOneField(User, on_delete = models.CASCADE)
    image = models.ImageField(default = 'default.jpg', upload_to='profile_pics')
    user_level = models.IntegerField(default = 1)

    def __str__(self):
        return '%s Profile' % self.account.username

我决定对模型进行更改,将 user_level 字段更改为 level_rank 并指定与不同模型中的字段的关系:

from django.db import models
from django.contrib.auth.models import User
from level_system.models import UserLevel
from PIL import Image

class Profile(models.Model):
    account = models.OneToOneField(User, on_delete = models.CASCADE)
    image = models.ImageField(default = 'default.jpg', upload_to='profile_pics')
    level_rank = models.ForeignKey(UserLevel, on_delete = models.SET_NULL, null = True)

    def __str__(self):
        return '%s Profile' % self.account.username

然后我运行 makemigrations 命令,但后来决定更改有关 Profile 模型的其他内容。

仅删除运行 makemigrations 命令时创建的迁移文件会产生什么后果?

本质上,我的问题是这会混淆迁移系统并损坏数据库,或者您可以自由删除尚未迁移的迁移文件吗?

我目前使用的是 Django v2.0.13

谢谢!

最佳答案

感谢那些评论的人。我决定冒险并在迁移之前删除迁移文件。我还没有遇到任何问题,尽管对我的模型的更改很小(仅更改了一个字段),因此对于阅读本文的任何人,我仍然建议谨慎行事。

关于python - 在运行 'migrate' 命令之前删除 Django 迁移文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55746740/

相关文章:

python - 使用字典定义图形和查找路径

python - 在 Django 1.5/1.6 中设置两种不同类型的用户

python - Django和Socket服务器: Can I add socket server instance to “memory” ?

python - 如何将 ruby​​ 解释器与我的应用程序一起分发

Python Falcon CORS 与 AJAX 错误

python - 如何更改 Jupyter Notebook 内核显示名称

django - celery :无法连接到rabbitmq

django 扩展了不同的基础模板

python - "I/O operation on closed file"在 Django View 测试中使用 StringIO

python - read_mrz 错误 : Could not find a format to read the specified file in mode 'i'