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

查看:58
本文介绍了'关系不存在'转移到 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)

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

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.

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

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