简体   繁体   English

无法进行迁移

[英]Can't make migrations

I write python3 manage.py makemigrations (I have a mac), migrations are not done, I get a lot of errors, but I don't understand anything about the project at all, here is the traceback我写了python3 manage.py makemigrations (我有一个mac),迁移没有完成,我得到了很多错误,但我根本不了解这个项目,这是回溯

Traceback (most recent call last):
  File "/Users/work/Projects/ims/api/manage.py", line 21, in <module>
    main()
  File "/Users/work/Projects/ims/api/manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/core/management/__init__.py", line 363, in execute
    settings.INSTALLED_APPS
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in __getattr__
    self._setup(name)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/conf/__init__.py", line 69, in _setup
    self._wrapped = Settings(settings_module)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/conf/__init__.py", line 170, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 855, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/work/Projects/ims/api/ims/settings.py", line 35, in <module>
    hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

ims/api/ims/settings.py ims/api/ims/settings.py

"""
Django settings for ims project.

Generated by 'django-admin startproject' using Django 2.2.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import os
import socket

import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY', 'mysecretkey')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DEBUG', False)

ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', 'example.com').split(',')

INTERNAL_IPS = os.environ.get('INTERNAL_IPS', '127.0.0.1').split(',')

hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS += [ip[:-1] + "1" for ip in ips]

# Application definition

INSTALLED_APPS = [
    # Locale apps
    'clients',
    'companies',
    'loyalty',
    'personnel',
    'products',
    'shops',
    'trades',

    # Third party apps
    'corsheaders',
    'django_filters',
    'djoser',
    'gtin_fields',
    'mptt',
    'rest_framework',
    'rest_framework.authtoken',

    # Django modules
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django_currentuser.middleware.ThreadLocalUserMiddleware',
]

ROOT_URLCONF = 'ims.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'ims/templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'ims.wsgi.application'

# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': os.environ.get('DATABASE_NAME'),
        'USER': os.environ.get('DATABASE_USER'),
        'PASSWORD': os.environ.get('DATABASE_PASSWORD'),
        'HOST': os.environ.get('DATABASE_HOST'),
        'PORT': os.environ.get('DATABASE_POST'),
    }
}

# MIGRATIONS
# https://docs.djangoproject.com/en/dev/ref/settings/#migration-modules

MIGRATION_MODULES = {
    'sites': 'sites.migrations',
}

# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

if not DEBUG:
    AUTH_PASSWORD_VALIDATORS = [
        {
            'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
        },
    ]

AUTH_USER_MODEL = 'companies.User'
SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'

EMAIL_HOST = os.environ.get('EMAIL_HOST', 'example.com')
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER', '')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD', '')
EMAIL_PORT = os.environ.get('EMAIL_PORT', 25)
EMAIL_USE_TLS = os.environ.get('EMAIL_USE_TLS', False)
EMAIL_USE_SSL = os.environ.get('EMAIL_USE_SSL', False)
DEFAULT_FROM_EMAIL = os.environ.get('DEFAULT_FROM_EMAIL', 'webmaster@example.com')

if DEBUG:
    EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'ru'

TIME_ZONE = 'Europe/Moscow'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Sites
# https://docs.djangoproject.com/en/2.1/ref/contrib/sites/#enabling-the-sites-framework

SITE_ID = 1
SITE_NAME = os.environ.get('SITE_NAME', None)
SITE_DOMAIN = os.environ.get('SITE_DOMAIN', None)

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'ims/static')]

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

# Sentry
# https://sentry.io/cryptoins-el/eplatform/getting-started/python-django/

SENTRY_DSN = os.environ.get('SENTRY_DSN', None)

sentry_sdk.init(
    dsn=SENTRY_DSN,
    integrations=[DjangoIntegration()]
)

# Django REST Framework
# https://www.django-rest-framework.org/

REST_FRAMEWORK = {
    'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.TokenAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    ),
    'TEST_REQUEST_DEFAULT_FORMAT': 'json',
}

# Django Cors Headers
# https://github.com/ottoyiu/django-cors-headers#setup

CORS_ORIGIN_ALLOW_ALL = True

# Django Debug Toolbar
# https://github.com/jazzband/django-debug-toolbar

if DEBUG:
    INSTALLED_APPS.append('debug_toolbar')
    MIDDLEWARE = ['debug_toolbar.middleware.DebugToolbarMiddleware', *MIDDLEWARE]
    DEBUG_TOOLBAR_CONFIG = {
        'SHOW_TOOLBAR_CALLBACK': lambda request: True,
    }

# djoser
# https://djoser.readthedocs.io/en/latest/settings.html

DJOSER = {
    'PASSWORD_RESET_CONFIRM_URL': 'password-reset/{uid}/{token}',
    'SET_PASSWORD_RETYPE': True,
    'USER_CREATE_PASSWORD_RETYPE': True,
    'SERIALIZERS': {
        'user_create_password_retype': 'ims.serializers.IMSUserCreatePasswordRetypeSerializer',
        'user': 'companies.serializers.UserCustomSerializer'
    }
}

edited /etc/hosts file and repeated the python3 manage.py makemigrations command and I got this error编辑/etc/hosts文件并重复python3 manage.py makemigrations命令,我收到此错误

Traceback (most recent call last):
  File "/Users/work/Projects/ims/api/manage.py", line 21, in <module>
    main()
  File "/Users/work/Projects/ims/api/manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
    django.setup()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/apps/config.py", line 224, in create
    import_module(entry)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'corsheaders'

teamlead in the team did something like migrations and they were applied, now, after I added indexes to models.py, to optimize sql queries, I needed to make migrations, but it did not work, but the server started without migrations团队中的teamlead做了类似migrations的事情,然后应用了,现在,在models.py中添加索引,优化sql查询后,需要进行migrations,但是没有成功,但是服务器启动时没有migrations

I don't know which files to show, because I don't understand the code in the project, because I'm new to django, but I'm always in touch and will throw off any files that you need我不知道要显示哪些文件,因为我不了解项目中的代码,因为我是 django 的新手,但我总是保持联系并且会扔掉您需要的任何文件

Thank you!谢谢!

You have set the machine hostname in etc/hosts file您已经在etc/hosts文件中设置了机器主机名

  1. find the machine name ( https://help.edovia.com/hc/en-us/articles/360002865213-Finding-your-computer-s-hostname-or-IP-address )找到机器名称( https://help.edovia.com/hc/en-us/articles/360002865213-Finding-your-computer-s-hostname-or-IP-address

  2. edit /etc/hosts file编辑 /etc/hosts 文件

    127.0.0.1 Naveens-MacBook-Pro.local (where Naveens-MacBook-Pro is my machine name) 127.0.0.1 Naveens-MacBook-Pro.local (其中 Naveens-MacBook-Pro 是我的机器名称)

Above changes are for MAC machine.以上变化是针对 MAC 机器的。

从头开始重新构建这个项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM