'关系不存在'转移到PostgreSQL后出错

时间:2016-12-17 14:36:21

标签: mysql django postgresql

我已将我的项目从MySQL转移到PostgreSQL并尝试删除该列作为上一期的结果,因为我从models.py中删除了有问题的列并保存。错误甚至没有消失。 Integer error transferring from MySQL to PostgreSQL

尝试使用和不使用引号。

ALTER TABLE "UserProfile" DROP COLUMN how_many_new_notifications;

或者:

ALTER TABLE UserProfile DROP COLUMN how_many_new_notifications;

获得以下内容:

ERROR:  relation "UserProfile" does not exist

这是一个模型,如果有帮助:

 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])

我认为它可能与混合案例有关但我找不到所有类似问题的解决方案。

2 个答案:

答案 0 :(得分:0)

是的,Postgresql是一个案例感知数据库,但django足够聪明,知道这一点。它转换所有字段,通常将模型名称转换为小写表名称。但是,这里真正的问题是您的模型名称将以应用程序名称为前缀。通常django表名称就像

<appname>_<modelname>

你可以通过

找出它究竟是什么
 from myapp.models import UserProfile
 print UserProfile._meta.db_table

显然这需要输入到django shell中,该shell由./manage.py shell调用,这个print语句的结果就是你应该在查询中使用的。

答案 1 :(得分:0)

  • 客户DataGrip
  • 数据库引擎:PostgreSQL

这对我来说打开新控制台有效,因为显然从IDE缓存中,它无法识别我创建的表。

Steps用于处理数据库表:

  1. 数据库(IDE的左侧面板)>
  2. 双击PostgreSQL-@localhost>
  3. 双击数据库名称>
  4. 右键单击公共架构>
  5. 新建>控制台

GL