Skip to content

Commit 3d3c869

Browse files
authored
Merge pull request #2 from David-Wobrock/master
Allow dropping a not null constraint
2 parents 236a526 + cef446a commit 3d3c869

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

django_better_migrations/rules.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ def process(self, migration, statements):
1111
return "OK"
1212

1313
def _incorrect(self, stmt):
14-
return stmt.startswith("ALTER TABLE") and "NOT NULL" in stmt
14+
return (
15+
stmt.startswith("ALTER TABLE") and
16+
"NOT NULL" in stmt and
17+
"DROP NOT NULL" not in stmt)

tests/test_rules.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import unittest
2+
3+
from django_better_migrations.rules import NoAddColumnNonNull
4+
5+
6+
class TestAddColumnNonNullRules(unittest.TestCase):
7+
def test_add_not_null_column(self):
8+
statements = (
9+
'ALTER TABLE "auth_user" ALTER COLUMN "username" NOT NULL;',
10+
)
11+
return_code = NoAddColumnNonNull().process(
12+
None,
13+
statements)
14+
self.assertEquals(return_code, "ERROR")
15+
16+
def test_drop_not_null_column(self):
17+
statements = (
18+
'ALTER TABLE "auth_user" ALTER COLUMN "username" DROP NOT NULL;',
19+
)
20+
return_code = NoAddColumnNonNull().process(
21+
None,
22+
statements)
23+
self.assertEquals(return_code, "OK")

0 commit comments

Comments
 (0)