问题描述:
makemigrations 的时候,能正常进行,但是当进行 migrate 的时候就抛出了 ValueError: Found wrong number (0) of constraints for …
解决办法:
因为修改了唯一约束索引,If you look at your actual table (use \d table_name
) and look at the indexes, you'll find an entry for your unique constraint. This is what Django is trying to find and drop. But it can't find an exact match(Postgres and MySQL Answer)
找到修改 unique_together 之前的包含 AlterUniqueTogether 的 migrations 文件,将上面的 unique_together 参数值,修改成与当前一致(增加或者删减,或者字段顺序)
修改完成以后,直接 migrate 即可。