Allow ignoring initial migrations

Sometimes, if your apps have cyclic dependencies or complicated FK structure,
django migrations creates multiple initial migration files, which can very
easily fail linting because they are adding foreign keys or constraints etc.

This adds an option to automatically ignore all initial migrations.
This commit is contained in:
Mikuláš Poul authored and David Wobrock committed 2025-03-30 19:29:56 +02:00
1 parent dfd83cf9b8
commit 979b6b1046
6 files changed
+35 -2

No files matched your search

+12
View File
@@ -170,3 +170,15 @@ class LinterFunctionsTestCase(unittest.TestCase):
]
)
self.assertEqual(2, len(list(migrations)))
def test_ignore_initial_migrations(self):
linter = MigrationLinter(ignore_initial_migrations=True)
self.assertTrue(
linter.should_ignore_migration(
"app_correct", "0001_initial", is_initial=True
)
)
self.assertFalse(
linter.should_ignore_migration("app_correct", "0002_foo", is_initial=False)
)