擅长:python、mysql、java
<p><strong>如果要保留数据库,但要减少迁移文件的数量,一个选项是将迁移</em>压缩为一个(或几个,如果是复杂的依赖项)迁移。</p>
<p>从官方文件来看:</p>
<blockquote>
<p>You are encouraged to make migrations freely and not worry about how many you have; the migration code is optimized to deal with hundreds at a time without much slowdown. However, eventually you will want to move back from having several hundred migrations to just a few, and that’s where squashing comes in.</p>
</blockquote>
<p>在压缩之前,您应该知道Django中的“<em>模型相互依赖关系可能会变得非常复杂,压缩可能会导致不运行</em>”的迁移,因此可能需要手动操作。</p>
<p>有关如何进行挤压的详细信息,请参阅文档:<a href="https://docs.djangoproject.com/en/dev/topics/migrations/#squashing-migrations" rel="nofollow noreferrer">https://docs.djangoproject.com/en/dev/topics/migrations/#squashing-migrations</a></p>