So I'm connecting my Django app to a SQL server database using django-mssql and pywin32-218.win-amd64-py2.7
Everything works great if I'm starting from scratch by creating models and syncing the database.
However, I'd like to connect to an existing SQL Server DB. I followed these instructions
And ended up with the following model:
from __future__ import unicode_literals
from django.db import models
class Payload(models.Model):
id = models.sqlserver_ado.fields.BigAutoField(db_column='Id') # Field name made lowercase.
code = models.CharField(db_column='Code', max_length=10) # Field name made lowercase.
body = models.TextField(db_column='Body') # Field name made lowercase.
class Meta:
managed = False
db_table = 'Payload'
If I try to run 'runserver' I get the following error:
File "C:\Users\luke\PycharmProjects\project\API\models.py", line 7, in Payload id = models.sqlserver_ado.fields.BigAutoField(db_column='Id') # Field name made lowercase. AttributeError: 'module' object has no attribute 'sqlserver_ado'
However, If I comment out the line "id = models.sqlserver_ado.fields.BigAutoField(db_column='Id') # Field name made lowercase."
Everything fires up perfectly.
Any ideas?!
If you are having sqlserver_ado installed. Import BigAutoField like this:
from sqlserver_ado.fields import BigAutoField
Then replace id = models.sqlserver_ado.fields.BigAutoField(db_column='Id') # Field name made lowercase
with
id = BigAutoField(db_column='Id') # Field name made lowercase.