繁体   English   中英

关系不存在Django迁移

[英]Relation does not exist django migrations

我正在EC2实例上部署django应用程序,并具有以下model.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',
]

查看showmigrations命令的输出,似乎问题在于您尚未为个人profiles应用创建任何迁移。

要解决此问题,请运行:

python manage.py makemigrations profiles
python manage.py migrate

或者,您可以忽略上述命令中的profiles ,以对需要它们的所有应用进行迁移。

暂无
暂无

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

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