Sql server 如何正确设置Django+;MS SQL+;mac上的Docker?

Sql server 如何正确设置Django+;MS SQL+;mac上的Docker?,sql-server,django,docker,Sql Server,Django,Docker,为什么会有这种特殊的组合 我需要创建一个与MS SQL数据库对话的网站,以显示公司的库存(数据库是由公司使用的专有软件创建的,因此切换到其他类型的数据库不是一个选项) 在过去的几个月里,我一直在学习Django和Python(通过官方文档、在线课程、个人项目),由于我开始了解一些事情,我认为我不应该突然切换到.NET或Node.JS,因为设置仍然有点神秘 我正在使用macbook,所以Docker是安装MS SQL Server的唯一方法(据我所知)。我确实有一个朋友给我的一台像样的电脑(只需

为什么会有这种特殊的组合

  • 我需要创建一个与MS SQL数据库对话的网站,以显示公司的库存(数据库是由公司使用的专有软件创建的,因此切换到其他类型的数据库不是一个选项)
  • 在过去的几个月里,我一直在学习Django和Python(通过官方文档、在线课程、个人项目),由于我开始了解一些事情,我认为我不应该突然切换到.NET或Node.JS,因为设置仍然有点神秘
  • 我正在使用macbook,所以Docker是安装MS SQL Server的唯一方法(据我所知)。我确实有一个朋友给我的一台像样的电脑(只需要设置一下),如果有人认为这能解决我所有的问题,我会继续切换
到目前为止我所做的/了解的(也许这对经历相同过程的人会有所帮助):

  • 有很多指南和教程解释了如何将Django与Postgre、SQLite等一起使用——看起来都很简单,所以我真正需要的是设置
  • 我已经在Docker容器中安装并运行了SQL Server(在和的帮助下)
  • 我已经成功地用一个.bak文件恢复了公司的数据库,并且我能够从命令行,通过Kitematic,当然还有ADS本身对其运行查询
  • 我尝试从一个新的Django项目连接到数据库(使用PyCharm,尽管这可能与此无关),使用这里概述的设置:我一直收到错误“image not found”,下面是控制台中的完整输出(以防有人发现有用的东西):


用户名、密码(***'d out)、主机IP和端口的特殊组合在Azure Data Studio中非常有效

  • 我已经按照以下指南将Django安装到另一个Docker容器中:不幸的是,这说明了如何使用Postgres进行安装,并且不清楚如何更改requirements.txt文件以使其与SQL server配合使用(我应该在其中放置什么来代替psycopg2>=2.7,
    Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x105ff5158>
    Traceback (most recent call last):
      File "/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/sql_server/pyodbc/base.py", line 15, in <module>
        import pyodbc as Database
    ImportError: dlopen(/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so, 2): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
      Referenced from: /Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so
      Reason: image not found
    
    During handling of the above exception, another exception occurred:
    
    *Traceback (most recent call last):
      File "/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/django/utils/autoreload.py", line 225, in wrapper
        fn(*args, **kwargs)
      File "/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
        autoreload.raise_last_exception()
      File "/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/django/utils/autoreload.py", line 248, in raise_last_exception
        raise _exception[1]
      File "/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/django/core/management/__init__.py", line 337, in execute
        autoreload.check_errors(django.setup)()
      File "/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/django/utils/autoreload.py", line 225, in wrapper
        fn(*args, **kwargs)
      File "/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
        apps.populate(settings.INSTALLED_APPS)
      File "/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/django/apps/registry.py", line 112, in populate
        app_config.import_models()
      File "/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/django/apps/config.py", line 198, in import_models
        self.models_module = import_module(models_module_name)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
      File "<frozen importlib._bootstrap>", line 983, in _find_and_load
      File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 728, in exec_module
      File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
      File "/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/django/contrib/auth/models.py", line 2, in <module>
        from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
      File "/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
        class AbstractBaseUser(models.Model):
      File "/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/django/db/models/base.py", line 101, in __new__
        new_class.add_to_class('_meta', Options(meta, app_label))
      File "/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/django/db/models/base.py", line 305, in add_to_class
        value.contribute_to_class(cls, name)
      File "/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/django/db/models/options.py", line 203, in contribute_to_class
        self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
      File "/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/django/db/__init__.py", line 33, in __getattr__
        return getattr(connections[DEFAULT_DB_ALIAS], item)
      File "/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/django/db/utils.py", line 202, in __getitem__
        backend = load_backend(db['ENGINE'])
      File "/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/django/db/utils.py", line 110, in load_backend
        return import_module('%s.base' % backend_name)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/sql_server/pyodbc/base.py", line 17, in <module>
        raise ImproperlyConfigured("Error loading pyodbc module: %s" % e)
    django.core.exceptions.ImproperlyConfigured: Error loading pyodbc module: dlopen(/Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so, 2): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
      Referenced from: /Users/student8/Desktop/GEMROVER/django_site/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so
      Reason: image not found*
    
        DATABASES = {
        'default': {
            'ENGINE': 'sql_server.pyodbc',
            'NAME': '*********',
            'USER': 'sa',
            'PASSWORD': '********',
            'HOST': '192.168.1.97',
            'PORT': '1433',
    
            'OPTIONS': {
                'driver': 'ODBC Driver 13 for SQL Server',
            },
        },
    }
    
    db:
        image: "mcr.microsoft.com/mssql/server"
        environment:
            SA_PASSWORD: "Your_password123"
            ACCEPT_EULA: "Y"
    
    brew install unixodbc
    
    Can't open lib 'ODBC Driver 13 for SQL Server'
    
    brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
    brew update
    brew install msodbcsql mssql-tools