File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -24,18 +24,23 @@ def check_custom_object_type_table_exists():
24
24
Check if the CustomObjectType table exists in the database.
25
25
Returns True if the table exists, False otherwise.
26
26
"""
27
+ from django .db import connection
27
28
from .models import CustomObjectType
28
29
29
30
try :
30
- # Try to query the model - if the table doesn't exist, this will raise an exception
31
- # this check and the transaction.atomic() is only required when running tests as the
32
- # migration check doesn't work correctly in the test environment
33
- with transaction .atomic ():
34
- # Force immediate execution by using first()
35
- CustomObjectType .objects .first ()
36
- return True
31
+ # Use raw SQL to check table existence without generating ORM errors
32
+ with connection .cursor () as cursor :
33
+ table_name = CustomObjectType ._meta .db_table
34
+ cursor .execute ("""
35
+ SELECT EXISTS (
36
+ SELECT FROM information_schema.tables
37
+ WHERE table_name = %s
38
+ )
39
+ """ , [table_name ])
40
+ table_exists = cursor .fetchone ()[0 ]
41
+ return table_exists
37
42
except (OperationalError , ProgrammingError , DatabaseError ):
38
- # Catch database-specific errors (table doesn't exist, permission issues, etc.)
43
+ # Catch database-specific errors (permission issues, etc.)
39
44
return False
40
45
41
46
You can’t perform that action at this time.
0 commit comments