gpt4 book ai didi

python - INSPECTDB 和 INSPECTDB_REFACTOR 生成空模型

转载 作者:行者123 更新时间:2023-11-29 12:50:44 25 4
gpt4 key购买 nike

我有一个 Django 项目和一个应用程序。我没有模型,我想从现有的 postgres 数据库生成它们。我尝试了 python manage.py inspectdb_refactor --database=default --app=igtpython manage.py inspectdb --database=default 但对于第一个事件 django 生成路径只有 __inti__.py,对于第二个事件 (inspectdb),django 生成空的 models.py。怎么了?连接正常(因此数据库配置正常),应用程序已在设置中定义.. 有什么问题?我的设置.py:

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os, sys
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.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '--------------------------------------------------'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']


# Application definition


MYOWN_APPS = [
'igt'
]

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'polymorphic',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'dynamic_raw_id',
'rest_framework',
'rest_framework_gis',
'django_filters',
'inspectdb_refactor',

] + MYOWN_APPS

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

ROOT_URLCONF = 'lesoved.urls'



TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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 = 'lesoved.wsgi.application'


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


DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'igt',
'USER': 'postgres',
'HOST': '00.xxxxxxxx',
'PASSWORD': 'xxxxxx',
'PORT': '0000',
}
}


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

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',
},
]


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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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


STATIC_URL = '/static/'

UPD:现在 inspectdb(迁移后)已经在 models.py 中生成了一些 Django 类:

class AuthGroup(models.Model):
name = models.CharField(unique=True, max_length=80)

class Meta:
managed = False
db_table = 'auth_group'


class AuthGroupPermissions(models.Model):
group = models.ForeignKey(AuthGroup, models.DO_NOTHING)
permission = models.ForeignKey('AuthPermission', models.DO_NOTHING)

class Meta:
managed = False
db_table = 'auth_group_permissions'
unique_together = (('group', 'permission'),)


class AuthPermission(models.Model):
name = models.CharField(max_length=255)
content_type = models.ForeignKey('DjangoContentType', models.DO_NOTHING)
codename = models.CharField(max_length=100)

class Meta:
managed = False
db_table = 'auth_permission'
unique_together = (('content_type', 'codename'),)

但是没有生成来自 postgres 数据库的类

最佳答案

使用公共(public)方案是个问题。我一直在数据库 (settings.py) 的选项配置中更改必要方案的公共(public)方案

DATABASE{
'default':{
//some configs
'OPTIONS': {
'options': '-c search_path=myownschema'
}
}
}

关于python - INSPECTDB 和 INSPECTDB_REFACTOR 生成空模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54557608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com