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():
2424 Check if the CustomObjectType table exists in the database.
2525 Returns True if the table exists, False otherwise.
2626 """
27+ from django .db import connection
2728 from .models import CustomObjectType
2829
2930 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
3742 except (OperationalError , ProgrammingError , DatabaseError ):
38- # Catch database-specific errors (table doesn't exist, permission issues, etc.)
43+ # Catch database-specific errors (permission issues, etc.)
3944 return False
4045
4146
You can’t perform that action at this time.
0 commit comments