SQL Server How can i create datetime2 model on Django

fivyi3re  于 2023-08-02  发布在  Go
关注(0)|答案(1)|浏览(92)

I do some research about this topic but i cannot find a solution.

`CreatedDate=models.DateTimeField(auto_now_add=True)`

when i create a model using this code, data type of mssql set as datetimeoffset(7).But i wish to create as type of datetime2(7).

I tried django-mssql-backend library.(It set as datetimeoffset(7)).I was expected datetime2.
https://stackoverflow.com/questions/65600327/sql-datetime27-field-to-django I followed the instructions here but the solution did not work for me

Shortly, how can i create datetime2 with using Django model?

cwtwac6a

cwtwac6a1#

The problem was releated with timezone.To solution:

  • Upload mssql-django
  • Set timezone ( USE_TZ = False ) as false in django settings, model created as datetime2.

相关问题