Django: Querying read-only view with no primary key

前端 未结 4 1106
广开言路
广开言路 2020-12-28 14:41
class dbview(models.Model):
    # field definitions omitted for brevity
    class Meta:
        db_table = \'read_only_view\'

def main(request):
    result = dbview         


        
4条回答
  •  有刺的猬
    2020-12-28 15:09

    There should have been an auto-generated id field when you ran syncdb (if there is no primary key defined in your model, then Django will insert an AutoField for you).

    This error means that Django is asking your database for the id field, but none exists. Can you run django manage.py dbshell and then DESCRIBE read_only_view; and post the result? This will show all of the columns that are in the database.

    Alternatively, can you include the model definition you excluded? (and confirm that you haven't altered the model definition since you ran syncdb?)

提交回复
热议问题