diff --git a/cachalot/tests/migrations/0001_initial.py b/cachalot/tests/migrations/0001_initial.py index 6d5fd67..41f11fc 100644 --- a/cachalot/tests/migrations/0001_initial.py +++ b/cachalot/tests/migrations/0001_initial.py @@ -74,4 +74,6 @@ class Migration(migrations.Migration): ('datetime_range', DateTimeRangeField(null=True, blank=True)), ], ), + migrations.RunSQL('CREATE TABLE cachalot_unmanagedmodel ' + '(id SERIAL PRIMARY KEY, name VARCHAR(50));'), ] diff --git a/cachalot/tests/models.py b/cachalot/tests/models.py index e3dc95a..fe109c1 100644 --- a/cachalot/tests/models.py +++ b/cachalot/tests/models.py @@ -62,3 +62,10 @@ class PostgresModel(Model): class Meta: # Tests schema name in table name. db_table = '"public"."cachalot_postgresmodel"' + + +class UnmanagedModel(Model): + name = CharField(max_length=50) + + class Meta: + managed = False diff --git a/cachalot/tests/read.py b/cachalot/tests/read.py index 676ef30..79a5cc9 100644 --- a/cachalot/tests/read.py +++ b/cachalot/tests/read.py @@ -20,7 +20,7 @@ from pytz import UTC from ..settings import cachalot_settings from ..utils import UncachableQuery -from .models import Test, TestChild, TestParent +from .models import Test, TestChild, TestParent, UnmanagedModel from .test_utils import TestUtilsMixin @@ -698,6 +698,11 @@ class ReadTestCase(TestUtilsMixin, TransactionTestCase): with connection.cursor() as cursor: cursor.execute('DROP TABLE %s;' % table_name) + def test_unmanaged_model(self): + qs = UnmanagedModel.objects.all() + self.assert_tables(qs, UnmanagedModel) + self.assert_query_cached(qs) + class ParameterTypeTestCase(TestUtilsMixin, TransactionTestCase): def test_tuple(self):