Django PostgreSQL DatabaseError:关系“类别”不存在 [英] Django PostgreSQL DatabaseError: relation "categories" does not exist

查看:272
本文介绍了Django PostgreSQL DatabaseError:关系“类别”不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个Django应用程序。最初我正在使用MySQL数据库。然后,我需要在使用PostgreSQL的heroku上部署一个演示应用程序。



当我尝试创建一个对象时,甚至从shell中我得到了一个英雄的错误。



这是我想要做的:

 > >从store.models import Product,Category 
>> cat = Category()
>> cat.name ='books'
>> cat.description ='books'
>> cat.slug ='books'
>> cat.save()

我收到以下错误:

  ...... 
DatabaseError:关系类别不存在

这是我的类别和产品型号

 类别(models.Model): 
name = models.CharField(max_length = 50)
description = models.TextField()
slug = models.SlugField(max_length = 50,unique = True)
created_at = models .DateTimeField(auto_now_add = True)
updated_at = models.DateTimeField(auto_now = True)

类产品(models.Model):
name = models.CharField(max_length = 100 ,unique = True)
description = models.TextField()
price = models.DecimalField(max_digits = 9,decimal_places = 2)
slug = models.SlugField(max_length = 50,unique =
category = models.ManyToManyField(Category)
created_at = models.DateTimeField(auto_now_add = True)
updated_at = models.DateTimeField(auto_now = True)

它与MySQL非常好,但不适用于PostgreSQL。





谢谢。

解决方案

您需要在heroku中运行syncdb所以它安装你的应用程序和模型。

  heroku运行python manage.py syncdb 

如果您对模式进行了更改,并且在南方使用,则:

  heroku run python manage.py schemamigration appname --auto 


I am working on a Django app. Initially I was using MySQL for database. Then, I needed to deploy a demo app on heroku, which uses PostgreSQL.

I am getting an error in heroku when I try to create an object, even from shell.

This is what I am trying to do:

>> from store.models import Product, Category
>> cat = Category()
>> cat.name = 'books'
>> cat.description = 'books'
>> cat.slug = 'books'
>> cat.save()

I get the following error:

......
DatabaseError: relation "categories" does not exist

Here's my Category and Product models

class Category(models.Model):
  name = models.CharField(max_length=50)
  description = models.TextField()
  slug = models.SlugField(max_length=50, unique=True)
  created_at = models.DateTimeField(auto_now_add=True)
  updated_at = models.DateTimeField(auto_now=True)

class Product(models.Model):
  name = models.CharField(max_length=100, unique=True)
  description = models.TextField()
  price = models.DecimalField(max_digits=9, decimal_places=2)
  slug = models.SlugField(max_length=50, unique=True)
  categories = models.ManyToManyField(Category)
  created_at = models.DateTimeField(auto_now_add=True)
  updated_at = models.DateTimeField(auto_now=True)

It works very well with MySQL, but not with PostgreSQL.

Can anyone help?

Thanks.

解决方案

You need to run syncdb in heroku as well so it installs your app and models.

heroku run python manage.py syncdb

If you made changes to your schema and you are using south then:

heroku run python manage.py schemamigration appname --auto

这篇关于Django PostgreSQL DatabaseError:关系“类别”不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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