0

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?

6
  • @DanielRoseman Yep. This is the weird thing. Commented Jan 28, 2014 at 23:56
  • 1
    Could it be a capitalization issue? Postgres converts table names to lowercase unless the queries have quotes around them: binodsblog.blogspot.com/2011/02/… Commented Jan 29, 2014 at 0:20
  • @CantucciHQ WOW what a surprise, I'd never suspect that could be the problem. Please answer the question so I can accept it :D Commented Jan 29, 2014 at 0:29
  • @Mauren That's SQL standard behaviour, btw, though the SQL spec says names should be upper-cased if not quoted. Commented Jan 29, 2014 at 2:47
  • 1
    @Mauren Oracle isn't known for following the spec closely ;-) . I'm not a fan of this particular SQL-spec behaviour. Commented Jan 29, 2014 at 12:38

2 Answers 2

2

The db_table name should be in lowercase:

db_table = 'item'
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.