Closed EstebanHelpDesk closed 11 months ago
For some newbie as me, I do it using a monkey patch in my settings.py under database specification. In same way I changed nvarchar to varchar to test speed.. but not the point here.
# Cambiar el tipo de datos datetime2 a datetime como default para coexistir con logica antigua y los sp de la base creada.
from mssql.base import DatabaseWrapper
DatabaseWrapper.data_types['DateTimeField'] = 'datetime'
# Cambiar el tipo de datos nvarchar a varchar para coexistir con los sp de la base creada manualmente.
DatabaseWrapper.data_types['CharField'] = 'varchar(%(max_length)s)'
I'm working with a mixed database that includes tables created using Django ORM and some manually crafted procedures. I've noticed that the datetime fields created in the database are of type datetime2. This becomes problematic when dealing with stored procedures that expect datetime.
I want to override this default behavior to create new models with datetime instead of datetime2. Is it possible to achieve this as a patch within my app without modifying the base.py file? some help or example here, please!
class DatabaseWrapper(BaseDatabaseWrapper): vendor = 'microsoft' display_name = 'SQL Server'
In this modified code, I changed the 'DateTimeField' entry from 'datetime2' to 'datetime' to address the issue with datetime fields. This adjustment should help avoid conflicts with stored procedures that rely on datetime rather than datetime2