【发布时间】:2019-02-04 20:21:08
【问题描述】:
我正在一个 EC2 实例上部署一个 django 应用程序,并且有以下 models.py:
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
foto = models.CharField(max_length=200, default="static/batman-for-
def __str__(self):
return str(self.user.first_name) + " Profile"
@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)
@receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwargs):
instance.profile.save()
当我使用 django 用户登录时,出现以下错误:
ProgrammingError at /admin/login/
relation "profiles_profile" does not exist
LINE 1: ..."."profiles_profile" FROM "profiles_...
来自:
/home/ubuntu/chimpy/profiles/models.py in save_user_profile
instance.profile.save()
我查看了 postgres 数据库,但找不到名为 Profile 的表,所以我猜我的迁移失败了,当我运行 python manage.py showmigrations 时它显示:
admin
[X] 0001_initial
[X] 0002_logentry_remove_auto_add
auth
[X] 0001_initial
[X] 0002_alter_permission_name_max_length
[X] 0003_alter_user_email_max_length
[X] 0004_alter_user_username_opts
[X] 0005_alter_user_last_login_null
[X] 0006_require_contenttypes_0002
[X] 0007_alter_validators_add_error_messages
[X] 0008_alter_user_username_max_length
[X] 0009_alter_user_last_name_max_length
contenttypes
[X] 0001_initial
[X] 0002_remove_content_type_name
sessions
[X] 0001_initial
但没有关于其他表(包括配置文件之一)。我还想提一下,当我在终端中创建超级用户时,出现以下错误:
django.db.utils.ProgrammingError: relation "profiles_profile" does not exist
LINE 1: INSERT INTO "profiles_profile" ("user_id", "foto", "exchange...
我做错了什么?谢谢。
编辑:我的 settings.py 包括以下内容:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'profiles',
'portfolios',
'django_extensions',
'rest_framework',
'corsheaders',
]
【问题讨论】:
-
包含
Profile类定义的应用名称是什么? -
@HenryWoody 名字是“profiles”
标签: python django postgresql amazon-web-services amazon-ec2