简体   繁体   English

在 Django 中应用迁移时反向返回 Postgres 字段类型

[英]Reverse back Postgres field type when migrations were applied in Django

I pulled the new code from GitHub and my colleagues changed the type of a field in a Django model from TextField to JSONField .我从 GitHub 中提取了新代码,我的同事将Django model 中的字段类型从TextField更改为JSONField After running python manage.py makemigrations and python manage.py migrate the type of the field was changed in the database (I suppose).运行python manage.py makemigrationspython manage.py migrate后,数据库中字段的类型发生了变化(我想)。 I needed to reverse back to previous migration and somehow the type of the field was not reversed .我需要退回到以前的迁移,并且不知何故该字段的类型没有反转 How could I fix the issue?我该如何解决这个问题? Why reversing back migration does not revert back the field type?为什么撤消迁移不会还原字段类型?

Change the field type back to a TextField, then run python manage.py makemigrations and python manage.py migrate again.将字段类型改回 TextField,然后再次运行python manage.py makemigrationspython manage.py migrate If the migration still exists in your django project, it will look at its dependencies , which most likely still links to the migration that turned it into a JSONField.如果您的 django 项目中仍然存在迁移,它将查看其dependencies项,这很可能仍链接到将其转换为 JSONField 的迁移。 So simply doing the exact same thing to turn it back into a TextField should work所以简单地做同样的事情把它变成一个 TextField 应该可以

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM