无法将MSSQL与Django连接

时间:2019-06-21 12:48:41

标签: python sql-server django django-models pymssql

我正在尝试将MSSQL Server与Django连接起来。我创建了一个数据库名称“ sample”。我的models.py中有一个名为“ Sales”的表。在我的settings.py中,我对数据库部分进行了如下编辑:

settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': "sample",
        'USER': appsdev,
        'PASSWORD': *******,
        'HOST': 'xx.xxx.xxx.xx',
        'PORT': 1433,
        'OPTIONS': {
            'driver': 'ODBC Driver 13 for SQL Server',
            'unicode_results': True,

        },
    }
}

我创建了一个名为“ sample_app”的应用,其中我的model.py为:

from django.db import models
from django_pandas.managers import DataFrameManager

class Sales(models.Model):
    Invoice_Date = models.CharField(max_length = 20, db_column = 'Invoice Date')
    Sales_Value = models.CharField(max_length = 20, db_column = 'Sales Value')
    City = models.CharField(max_length = 60, db_column = 'City')

    objects = models.Manager()
    pdobjects = DataFrameManager()

    def __str__(self):
            field_values = []
            for field in self._meta.get_fields():
                field_values.append(str(getattr(self, field.name, '')))
            return ' '.join(field_values)

当我尝试进行迁移时,出现类似这样的错误

django.db.utils.ProgrammingError:<'42S02',"[42S02][Microsoft][ODBC Driver13 for SQL Server][SQL Server][Invalid object name ' sample_app_sales'.<208><SQLExecDirectW>">

已安装的库列表

alabaster==0.7.10
anaconda-client==1.6.14
anaconda-navigator==1.8.7
anaconda-project==0.8.2
appdirs==1.4.3
applescript==2018.11.19
arrow==0.13.0
asn1crypto==0.24.0
astroid==1.6.3
astropy==3.0.2
attrs==18.1.0
Babel==2.5.3
backcall==0.1.0
backports.shutil-get-terminal-size==1.0.0
beautifulsoup4==4.6.0
bitarray==0.8.1
bkcharts==0.2
blaze==0.11.3
bleach==2.1.3
blis==0.2.4
bokeh==0.12.16
boto==2.48.0
Bottleneck==1.2.1
bs4==0.0.1
cachetools==3.0.0
certifi==2018.4.16
cffi==1.11.5
chardet==3.0.4
click==6.7
cloudpickle==0.5.3
clyent==1.2.2
colorama==0.3.9
colorlover==0.3.0
comtypes==1.1.4
conda==4.5.11
conda-build==3.10.5
conda-verify==2.0.0
contextlib2==0.5.5
cryptography==2.2.2
cufflinks==0.14.6
cycler==0.10.0
cymem==2.0.2
Cython==0.28.2
cytoolz==0.9.0.1
dask==0.17.5
datashape==0.5.4
decorator==4.3.0
defusedxml==0.5.0
detect==2018.11.19
diff-match-patch==20181111
dill==0.2.8.2
distributed==1.21.8
Django==2.1.7
django-crispy-forms==1.7.2
django-filter==2.1.0
django-import-export==1.2.0
django-mssql==1.8
django-mysql==2.5.0
django-pandas==0.6.0
django-pyodbc-azure==2.1.0.0
djangorestframework==3.9.2
docutils==0.14
entrypoints==0.2.3
et-xmlfile==1.0.1
fastcache==1.0.2
filelock==3.0.4
fiscalyear==0.1.0
Flask==1.0.2
Flask-Cors==3.0.4
gevent==1.3.0
glob2==0.6
google-api-python-client==1.7.7
google-auth==1.6.2
google-auth-httplib2==0.0.3
greenlet==0.4.13
gTTS==2.0.3
gTTS-token==1.1.3
h5py==2.7.1
heapdict==1.0.0
html5lib==1.0.1
httplib2==0.12.0
idna==2.6
imageio==2.3.0
imagesize==1.0.0
imbalanced-learn==0.4.3
ipykernel==4.8.2
ipython==6.4.0
ipython-genutils==0.2.0
ipywidgets==7.2.1
isort==4.3.4
itsdangerous==0.24
jdcal==1.4
jedi==0.12.0
Jinja2==2.10
jsonschema==2.6.0
jupyter==1.0.0
jupyter-client==5.2.3
jupyter-console==5.2.0
jupyter-core==4.4.0
jupyterlab==0.32.1
jupyterlab-launcher==0.10.5
kiwisolver==1.0.1
lazy-object-proxy==1.3.1
llvmlite==0.23.1
locket==0.2.0
lxml==4.2.1
Markdown==3.0.1
MarkupSafe==1.0
matplotlib==2.2.2
mccabe==0.6.1
menuinst==1.4.14
mistune==0.8.3
mkl-fft==1.0.0
mkl-random==1.0.1
monotonic==1.5
more-itertools==4.1.0
mpg123==0.4
mpmath==1.0.0
msgpack==0.5.6
msgpack-numpy==0.4.3.2
msgpack-python==0.5.6
multipledispatch==0.5.0
murmurhash==1.0.1
mysqlclient==1.4.2.post1
navigator-updater==0.2.1
nbconvert==5.3.1
nbformat==4.4.0
networkx==2.1
nltk==3.3
nose==1.3.7
notebook==5.5.0
numba==0.38.0
numexpr==2.6.5
numpy==1.16.3
numpydoc==0.8.0
odfpy==1.4.0
odo==0.5.1
olefile==0.45.1
only==2018.11.20
Open-Tamil==0.8
openpyxl==2.5.3
packaging==17.1
pandas==0.23.0
pandocfilters==1.4.2
parso==0.2.0
partd==0.3.8
path.py==11.0.1
pathlib2==2.3.2
patsy==0.5.0
pep8==1.7.1
pickleshare==0.7.4
Pillow==5.1.0
pkginfo==1.4.2
plac==0.9.6
playsound==1.2.2
plotly==3.6.0
pluggy==0.6.0
ply==3.11
preshed==2.0.1
prompt-toolkit==1.0.15
psutil==5.4.5
public==2018.11.20
py==1.5.3
pyasn1==0.4.5
pyasn1-modules==0.2.3
PyAudio==0.2.11
pycodestyle==2.4.0
pycosat==0.6.3
pycparser==2.18
pycrypto==2.6.1
pycurl==7.43.0.1
pyflakes==1.6.0
pygame==1.9.4
Pygments==2.2.0
pylint==1.8.4
pyodbc==4.0.23
Pyomo==5.6
pyOpenSSL==18.0.0
pyparsing==2.2.0
pypiwin32==223
pyreadline==2.1
PySocks==1.6.8
pytest==3.5.1
pytest-arraydiff==0.2
pytest-astropy==0.3.0
pytest-doctestplus==0.1.3
pytest-openfiles==0.3.0
pytest-remotedata==0.2.1
python-dateutil==2.7.3
pyttsx3==2.7
pytz==2018.4
PyUtilib==5.6.4
PyWavelets==0.5.2
pywin32==223
pywinpty==0.5.1
pyxlsb==1.0.4
PyYAML==3.12
pyzmq==17.0.0
QtAwesome==0.4.4
qtconsole==4.3.1
QtPy==1.4.1
regex==2018.8.29
requests==2.18.4
retrying==1.3.3
rope==0.10.7
rsa==4.0
ruamel-yaml==0.15.35
runcmd==2018.12.14
scikit-image==0.13.1
scikit-learn==0.20.2
scipy==1.1.0
seaborn==0.8.1
Send2Trash==1.5.0
simplegeneric==0.8.1
singledispatch==3.4.0.3
six==1.11.0
snowballstemmer==1.2.1
sortedcollections==0.6.1
sortedcontainers==1.5.10
spacy==2.1.3
speech==0.5.2
SpeechRecognition==3.8.1
Sphinx==1.7.4
sphinxcontrib-websupport==1.0.1
spyder==3.2.8
SQLAlchemy==1.2.7
srsly==0.0.5
statsmodels==0.9.0
sympy==1.1.1
tables==3.4.3
tablib==0.12.1
tblib==1.3.2
temp==2018.11.20
termcolor==1.1.0
terminado==0.8.1
testpath==0.3.1
thinc==7.0.4
toolz==0.9.0
tornado==5.0.2
tqdm==4.28.1
traitlets==4.3.2
typing==3.6.4
unicodecsv==0.14.1
uritemplate==3.0.0
urllib3==1.22
vlc==2018.11.20
wasabi==0.2.1
wcwidth==0.1.7
webencodings==0.5.1
Werkzeug==0.14.1
widgetsnbextension==3.2.1

我已将用户权限设置为“所有者”级别,以便用户可以访问所有内容。
我也尝试过“ python manage.py migration”。但这是行不通的。数据库的默认架构设置为“ dbo”。我不知道我要去哪里错了。请帮助我解决这个问题。

谢谢

0 个答案:

没有答案