python - django多表查询
大家讲道理
大家讲道理 2017-04-18 09:23:19
0
2
230
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就好。
谢谢了

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
洪涛

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

刘奇

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template