diff --git a/django_migration_linter/sql_analyser/base.py b/django_migration_linter/sql_analyser/base.py index 584ebbc..a74b40f 100644 --- a/django_migration_linter/sql_analyser/base.py +++ b/django_migration_linter/sql_analyser/base.py @@ -8,7 +8,7 @@ logger = logging.getLogger("django_migration_linter") def has_not_null_column(sql_statements, **kwargs): # TODO: improve to detect that the same column is concerned - ends_with_default = None + ends_with_default = False for sql in sql_statements: if "SET DEFAULT" in sql: ends_with_default = True diff --git a/tests/unit/test_sql_analyser.py b/tests/unit/test_sql_analyser.py index bb30d99..00dd50e 100644 --- a/tests/unit/test_sql_analyser.py +++ b/tests/unit/test_sql_analyser.py @@ -171,6 +171,21 @@ class PostgresqlAnalyserTestCase(SqlAnalyserTestCase): ] self.assertValidSql(sql) + def test_field_to_not_null_with_dropped_default(self): + sql = [ + 'ALTER TABLE "api_example_example" ALTER COLUMN "foo_id" SET DEFAULT 42;', + 'UPDATE "example_example" SET "foo_id" = 42 WHERE "foo_id" IS NULL;', + 'ALTER TABLE "example_example" ALTER COLUMN "foo_id" SET NOT NULL;', + 'ALTER TABLE "example_example" ALTER COLUMN "foo_id" DROP DEFAULT;', + ] + self.assertBackwardIncompatibleSql(sql) + + def test_onetoonefield_to_not_null(self): + sql = [ + 'ALTER TABLE "example_example" ALTER COLUMN "foo" SET NOT NULL;', + ] + self.assertBackwardIncompatibleSql(sql) + def test_drop_not_null(self): sql = 'ALTER TABLE "app_alter_column_drop_not_null_a" ALTER COLUMN "not_null_field" DROP NOT NULL;' self.assertValidSql(sql)