Django PostgreSQL DatabaseError:关系“类别”不存在 [英] Django PostgreSQL DatabaseError: relation "categories" does not exist
问题描述
当我尝试创建一个对象时,甚至从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屋!