MySQL gives an “Unknown column 'user.id' in 'field list'” error using Django's automatic id

前端 未结 2 1987
一整个雨季
一整个雨季 2021-01-26 11:23

I have my User model set up with no primary key so that the automatic id will be used instead. However, when I try to access it using Django\'s \"

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-26 11:46

    Not 100% sure, but I think even though Django will add the id field to the model class, that field will not propagate to the DB with syncdb.

    One way to try it would be to rename the existing User table, run syncdb and see if the User table is created. If not (which is likely because of the managed flag) try again with managed=True. If the id field appears in this case then my guess is you'll have to add it manually to the User table with the same parameters as the automatically created one.

提交回复
热议问题