mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #373 -- Added CompositePrimaryKey.
Thanks Lily Foote and Simon Charette for reviews and mentoring this Google Summer of Code 2024 project. Co-authored-by: Simon Charette <charette.s@gmail.com> Co-authored-by: Lily Foote <code@lilyf.org>
This commit is contained in:
committed by
Sarah Boyce
parent
86661f2449
commit
978aae4334
@@ -1206,6 +1206,28 @@ class StateTests(SimpleTestCase):
|
||||
choices_field = Author._meta.get_field("choice")
|
||||
self.assertEqual(list(choices_field.choices), choices)
|
||||
|
||||
def test_composite_pk_state(self):
|
||||
new_apps = Apps(["migrations"])
|
||||
|
||||
class Foo(models.Model):
|
||||
pk = models.CompositePrimaryKey("account_id", "id")
|
||||
account_id = models.SmallIntegerField()
|
||||
id = models.SmallIntegerField()
|
||||
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
apps = new_apps
|
||||
|
||||
project_state = ProjectState.from_apps(new_apps)
|
||||
model_state = project_state.models["migrations", "foo"]
|
||||
self.assertEqual(len(model_state.options), 2)
|
||||
self.assertEqual(model_state.options["constraints"], [])
|
||||
self.assertEqual(model_state.options["indexes"], [])
|
||||
self.assertEqual(len(model_state.fields), 3)
|
||||
self.assertIn("pk", model_state.fields)
|
||||
self.assertIn("account_id", model_state.fields)
|
||||
self.assertIn("id", model_state.fields)
|
||||
|
||||
|
||||
class StateRelationsTests(SimpleTestCase):
|
||||
def get_base_project_state(self):
|
||||
|
||||
Reference in New Issue
Block a user