部署多租户应用程序 (django-tenant) - 错误 运行 ./manage migrate_schemas
Deploying a multi tenant application (django-tenant) - Error to run ./manage migrate_schemas
我在 AWS 上托管了一个 django 应用程序 - Web client <=> nginx <=> uwsgi <=> django
。我决定使用 django-tenant 将其转换为多租户。此外,我正在使用 django-celery-beat 来安排任务。我的单一应用程序在 AWS 上正常工作,我的多租户也在我的机器上本地工作。我在识别芹菜模式时遇到了问题,但我在这里解决了它:。但是,我现在遇到的错误是在我的 VPN 中:django.db.utils.ProgrammingError: relation" app_modelcustomuser "does not exist
当我尝试 运行 ./manage migrate_schemas
(我在我的本地机器上进行 makemigration 并提交它,所以我只需要迁移到我的 VPN 中的数据库)或任何其他迁移时出现.我尝试按应用程序迁移,当我这样做时我得到了它 ./manage migrate admin
。我的 settings.py 文件如下所示:
SHARED_APPS = [
'django_tenants',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'clients',
]
TENANT_APPS = [
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
# Libs
'stdimage',
'django_celery_beat',
'djcelery_email',
'tenant_schemas_celery',
# 'widget_tweaks',
'bootstrap4',
'bootstrapform',
mathfilters,
'django_filters',
'sorl.thumbnail',
# Apps
'presence',
'confirmed list',
'topper',
'app_users.apps.AppUsersConfig',
]
INSTALLED_APPS = list (set (SHARED_APPS + TENANT_APPS))
AUTH_USER_MODEL = 'app_users.ModelCustomUser'
PUBLIC_SCHEMA_URLCONF = 'myproject.urls_public'
# Django Tenant
TENANT_MODEL = "clients.Client" # app.Model
TENANT_DOMAIN_MODEL = "clients.Domain" # app.Model
DATABASE_ROUTERS = (
'django_tenants.routers.TenantSyncRouter',
)
我的models.py(app应用):
class ModelCustomUser (AbstractUser):
image = ImageField (
'Image',
upload_to = 'images',
default = 'images/new_logo.png',
)
我的forms.py:
class CustomUserCreationForm (UserCreationForm):
class Goal:
model = ModelCustomUser
# Changed when placing the Filters
fields = ('first_name', 'last_name', 'username', 'email', 'image')
class CustomUserChangeForm (UserChangeForm):
class Goal:
model = ModelCustomUser
fields = ('first_name', 'last_name', 'username', 'email', 'image')
我的admin.py:
class AdminCustomUser (UserAdmin):
add_form = CustomUserCreationForm
form = CustomUserChangeForm
model = ModelCustomUser
# list_display = ['first_name', 'last_name', 'email', 'username', 'image']
list_display = ['first_name', 'last_name', 'email', 'username', 'image']
admin.site.register (ModelCustomUser, AdminCustomUser)
在我的客户应用程序中,我的 models.py:
class Client(TenantMixin):
name = models.CharField(max_length=100)
# default true, schema will be automatically created and synced when it is saved
auto_create_schema = True
def __str__(self):
return self.name
class Domain(DomainMixin):
pass
我已经尝试纠正这个问题很长时间了,但一直没有成功。如果有人能帮助我,我真的很感激!
我的错误是初学者错误。当我部署我的单一应用程序时,数据库没有改变,我离开了 db.sqlite3。当我切换到多租户时,我不得不切换到 PostgreSQL。我的问题是因为我需要 运行:
python manage.py collectstatic
我在 AWS 上托管了一个 django 应用程序 - Web client <=> nginx <=> uwsgi <=> django
。我决定使用 django-tenant 将其转换为多租户。此外,我正在使用 django-celery-beat 来安排任务。我的单一应用程序在 AWS 上正常工作,我的多租户也在我的机器上本地工作。我在识别芹菜模式时遇到了问题,但我在这里解决了它:django.db.utils.ProgrammingError: relation" app_modelcustomuser "does not exist
当我尝试 运行 ./manage migrate_schemas
(我在我的本地机器上进行 makemigration 并提交它,所以我只需要迁移到我的 VPN 中的数据库)或任何其他迁移时出现.我尝试按应用程序迁移,当我这样做时我得到了它 ./manage migrate admin
。我的 settings.py 文件如下所示:
SHARED_APPS = [
'django_tenants',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'clients',
]
TENANT_APPS = [
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
# Libs
'stdimage',
'django_celery_beat',
'djcelery_email',
'tenant_schemas_celery',
# 'widget_tweaks',
'bootstrap4',
'bootstrapform',
mathfilters,
'django_filters',
'sorl.thumbnail',
# Apps
'presence',
'confirmed list',
'topper',
'app_users.apps.AppUsersConfig',
]
INSTALLED_APPS = list (set (SHARED_APPS + TENANT_APPS))
AUTH_USER_MODEL = 'app_users.ModelCustomUser'
PUBLIC_SCHEMA_URLCONF = 'myproject.urls_public'
# Django Tenant
TENANT_MODEL = "clients.Client" # app.Model
TENANT_DOMAIN_MODEL = "clients.Domain" # app.Model
DATABASE_ROUTERS = (
'django_tenants.routers.TenantSyncRouter',
)
我的models.py(app应用):
class ModelCustomUser (AbstractUser):
image = ImageField (
'Image',
upload_to = 'images',
default = 'images/new_logo.png',
)
我的forms.py:
class CustomUserCreationForm (UserCreationForm):
class Goal:
model = ModelCustomUser
# Changed when placing the Filters
fields = ('first_name', 'last_name', 'username', 'email', 'image')
class CustomUserChangeForm (UserChangeForm):
class Goal:
model = ModelCustomUser
fields = ('first_name', 'last_name', 'username', 'email', 'image')
我的admin.py:
class AdminCustomUser (UserAdmin):
add_form = CustomUserCreationForm
form = CustomUserChangeForm
model = ModelCustomUser
# list_display = ['first_name', 'last_name', 'email', 'username', 'image']
list_display = ['first_name', 'last_name', 'email', 'username', 'image']
admin.site.register (ModelCustomUser, AdminCustomUser)
在我的客户应用程序中,我的 models.py:
class Client(TenantMixin):
name = models.CharField(max_length=100)
# default true, schema will be automatically created and synced when it is saved
auto_create_schema = True
def __str__(self):
return self.name
class Domain(DomainMixin):
pass
我已经尝试纠正这个问题很长时间了,但一直没有成功。如果有人能帮助我,我真的很感激!
我的错误是初学者错误。当我部署我的单一应用程序时,数据库没有改变,我离开了 db.sqlite3。当我切换到多租户时,我不得不切换到 PostgreSQL。我的问题是因为我需要 运行:
python manage.py collectstatic