2012-07-02 72 views
4

我正在使用Django應用程序。最初我使用MySQL作爲數據庫。然後,我需要在使用PostgreSQL的heroku上部署一個演示應用程序。Django PostgreSQL DatabaseError:關係「類別」不存在

當我嘗試創建一個對象時,即使從shell中,我也遇到了錯誤。

這就是我要做的:

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

我收到以下錯誤:

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

這裏是我的類別和產品型號

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) 

它非常好與MySQL,但不與PostgreSQL。

任何人都可以幫忙嗎?

謝謝。

+1

漂亮的直線前進。無論出於何種原因,該字段實際上並不在您的數據庫表上。運行'python manage.py dbshel​​l',然後在提示符處輸入'\ d + yourapp_product'來查看當前狀態。 –

回答

6

您需要在heroku中運行syncdb,因此它會安裝您的應用程序和模型。

heroku run python manage.py syncdb 

如果你更改了你的架構和你使用的南則:

heroku run python manage.py schemamigration appname --auto