search

Home  >  Q&A  >  body text

python - django多表查询

class ad_type(models.Model):
    id=models.AutoField(primary_key=True, db_column='id')
    class Meta:
            db_table = 'ad_type'


class ad_list(models.Model):
    id=models.AutoField(primary_key=True, db_column='id')
    ad_type=models.ForeignKey(ad_type)
    class Meta:
            db_table = 'ad_list'

然后进行查询:ad_list.objects.all()
提示错误:
"Unknown column 'ad_list.ad_type_id' in 'field list'"
是哪里没写对吗?只要换成外键就出错,换成Int就好。
谢谢了

大家讲道理大家讲道理2892 days ago235

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 09:25:19

    The prompt has clearly pointed out that the table ad_list does not have the column ad_type_id, which means that you did not update the table after writing the model

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 09:25:19

    You may have changed the primary key but not migrated it. In my case, the test worked! Try the following two commands.

    python manage.py makemigrations
    python manage.py migrate

    reply
    0
  • Cancelreply