开发者

django models to work with database views,tables

My database has the tables books[isbn,name,author,availableNum],students[name,major,coursestaking],course[name,department,number,capacity,booksNeeded],department[name,courses] I have a small view that has fields fr开发者_StackOverflow中文版om all the above {courseName,booksRecommended,dept,countofstudents}. When creating a model for view should I say something like this.

class Lookup(models.Model):
    course = models.ForeignKey('course',db_column = 'name')
    booksRecommended = models.ForeignKey('books',db_column = 'isbn')
    dept = models.ForeignKey('department',db_column = 'name')
    studentcount = models.IntegerField()

I'm getting the error ProgrammingError: column lookup.id does not exist. Ideas are welcome


The models.Model that you have inherited from assumes that the table (or the view, in your case) has a column called as id that is used as a primary key, unless you have explicitly marked some other column to be primary_key = True.

Your view's sql, or the ./manage.py inspectdb should help us find the primary key for this view.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜