转移到PostgreSQL后出现“不存在关系”错误 [英] 'Relation does not exist' error after transferring to PostgreSQL

查看:663
本文介绍了转移到PostgreSQL后出现“不存在关系”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将项目从MySQL转移到PostgreSQL,并尝试删除上一列的结果,这是因为上一期的问题是因为在我从models.py中删除了有问题的列并保存之后。错误甚至没有消失。 从MySQL传输到PostgreSQL的整数错误

I have transfered my project from MySQL to PostgreSQL and tried to drop the column as result of previous issue, because after I removed the problematic column from models.py and saved. error didn't even disappear. Integer error transferring from MySQL to PostgreSQL

尝试使用带引号和不使用引号。

Tried both with and without quotes.

ALTER TABLE "UserProfile" DROP COLUMN how_many_new_notifications;

或:

ALTER TABLE UserProfile DROP COLUMN how_many_new_notifications;

获取以下信息:

ERROR:  relation "UserProfile" does not exist

如果有一个模型,帮助:

Here's a model, if helps:

 class UserProfile(models.Model):
    user = models.OneToOneField(User)
    how_many_new_notifications = models.IntegerField(null=True,default=0)
User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])

我认为这可能与混合大小写有关,但是我发现所有类似问题都没有解决方案。

I supposed it might have something to do with mixed-case but I have found no solution through all similar questions.

推荐答案

是的,Postgresql是一个区分大小写的数据库,但是django足够聪明。它会转换所有字段,并且通常会将模型名称转换为小写表格名称。但是,这里真正的问题是您的型号名称将以应用程序名称为前缀。通常django表名称如下:

Yes, Postgresql is a case aware database but django is smart enough to know that. It converts all field and it generally converts the model name to a lower case table name. However the real problem here is that your model name will be prefixed by the app name. generally django table names are like:

<appname>_<modelname>

您可以通过以下方式找出确切的含义:

You can find out what exactly it is by:

from myapp.models import UserProfile
print (UserProfile._meta.db_table)

显然,这需要输入到django shell中,由调用。/manage.pyshell 该打印语句的结果就是您在查询中使用的结果。

Obviously this needs to be typed into the django shell, which is invoked by ./manage.py shell the result of this print statement is what you should use in your query.

这篇关于转移到PostgreSQL后出现“不存在关系”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆