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就好。
谢谢了
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.