当前位置: 动力学知识库 > 问答 > 编程问答 >

python - "Relation not found" error when using Django without syncdb

问题描述:

I have a small Django project with simple models. However, instead of creating my database via python manage.py syncdb I decided to create it manually and map the tables via Meta, as shown below

class Item(models.Model):

name = models.CharField(max_length=50)

class Meta:

managed = False

db_table = 'ITEM'

but this doesn't work. When I start the development server and run the main view, Django throws an error saying that the relation named ITEM doesn't exist in the database, when in fact it does exist.

I have done some research but couldn't find anyone with such a problem. Is there a way I can get it working?

网友答案:

Postgres converts table names to lowercase letters unless the queries have quotes around them. See for example:

http://binodsblog.blogspot.com/2011/02/postgresql-is-case-sensitive.html

Normally that detail is abstracted away by the ORM, but if you don't use syncdb, you have to manage it.

网友答案:

The db_table name should be in lowercase:

db_table = 'item'
分享给朋友:
您可能感兴趣的文章:
随机阅读: